How can I localize data returned from the database? For example, I have a data-bound label for CompensationType. If it returns the value "2" how can I localize that "2"? I already have the resource files setup and ready.
All the examples that I have seen localize static data, I can't find anything that localizes data returned from the database.
BTW - I know how to dynamically create a drop-down list and bind the selected value, that works just fine. I just need to figure out what to do with the label...
Thanks for the reply mm10. In case anyone else has a similar problem, the following is the solution I decided on. I am using DNN so some of the code below may seem a little weird.
On the DataBound event of the DetailsView, localize the data in the label control.
Private Sub LocalizeCompTypeDataLabel()
Try
Dim lblCompensationTypeData As Label = CType(dvwOffer.FindControl("lblCompensationTypeData"), Label)
If Not IsNothing(lblCompensationTypeData) Then
'Use the CompType resource file
Dim strResourceFilePath As String = Me.TemplateSourceDirectory & "/" & Services.Localization.Localization.LocalResourceDirectory & "/CompType.ascx"
lblCompensationTypeData.Text = Localization.GetString(lblCompensationTypeData.Text, strResourceFilePath)
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
deusbelli
Member
1 Points
19 Posts
Returned data localization
Apr 05, 2012 07:24 AM|LINK
How can I localize data returned from the database? For example, I have a data-bound label for CompensationType. If it returns the value "2" how can I localize that "2"? I already have the resource files setup and ready.
All the examples that I have seen localize static data, I can't find anything that localizes data returned from the database.
BTW - I know how to dynamically create a drop-down list and bind the selected value, that works just fine. I just need to figure out what to do with the label...
mm10
Contributor
6445 Points
1187 Posts
Re: Returned data localization
Apr 07, 2012 05:54 PM|LINK
//Using IFormatProvider
int val = 2;
Label1.Text = val.ToString("N", new CultureInfo("fr-FR")));
deusbelli
Member
1 Points
19 Posts
Re: Returned data localization
Apr 08, 2012 05:07 AM|LINK
Thanks for the reply mm10. In case anyone else has a similar problem, the following is the solution I decided on. I am using DNN so some of the code below may seem a little weird.
On the DataBound event of the DetailsView, localize the data in the label control.
Private Sub LocalizeCompTypeDataLabel()
Try
Dim lblCompensationTypeData As Label = CType(dvwOffer.FindControl("lblCompensationTypeData"), Label)
If Not IsNothing(lblCompensationTypeData) Then
'Use the CompType resource file
Dim strResourceFilePath As String = Me.TemplateSourceDirectory & "/" & Services.Localization.Localization.LocalResourceDirectory & "/CompType.ascx"
lblCompensationTypeData.Text = Localization.GetString(lblCompensationTypeData.Text, strResourceFilePath)
End If
Catch exc As Exception 'Module failed to load
ProcessModuleLoadException(Me, exc)
End Try
End Sub
Some sample data from the RESX file:
Name Value
Charity.Text Charity
Commission.Text Commission
Salary.Text Salary