Hi...
Please let me know what does the localization.getsting wil do?
Is there any method called GetString in your application?
How u r catching the key pair of a resource file?
Please respond fast......
Thnx in advance.
William Severance wrote
Needing to localize a GridView control's header text as well as the captions on the buttons in a CommandField, I wrote the following:
Public Shared Sub LocalizeGridView(ByVal gv As GridView, ByVal ResourceFile As String)
Dim key As String
Dim localizedText As String
Dim pi As System.Reflection.PropertyInfo
For Each col As DataControlField In gv.Columns
key = col.HeaderText
If key <> "" Then
localizedText = Localization.GetString(key & ".Header", ResourceFile)
If localizedText <> "" Then
col.HeaderText = localizedText
End If
End If
'Localize text of Cancel, Delete, Edit, Insert, Select, New, Update buttons
If TypeOf col Is CommandField Then
Dim cmdField As CommandField = DirectCast(col, CommandField)
For Each cmdName As String In New String() {"Cancel", "Delete", "Edit", "Insert", "Select", "New", "Update"}
pi = cmdField.GetType.GetProperty(cmdName & "Text", GetType(String))
key = CType(pi.GetValue(cmdField, Nothing), String)
If Not String.IsNullOrEmpty(key) Then
localizedText = Localization.GetString(key & ".CommandText", ResourceFile)
If localizedText <> "" Then
pi.SetValue(cmdField, localizedText, Nothing)
End If
End If
Next
End If
Next
End Sub
In the local resource file, the keys for Header text should end with .Header while the keys for the CommandField button captions should end with .CommandText. In a CommandField, the EditText, CancelText, etc. default to "Edit", "Cancel", etc. so unless the defaults are overridden in the CommandField declaration, use keys of "Edit.CommandText", "Cancel.CommandText", etc. in the resource file.
I'm not sure if my use of reflection in getting and setting the captions of the CommandField buttons is the most efficient performance wise, it was quick to write using fewer statements.
Hope this is helpful to someone!