Answered by:
Localized GridView

Question
-
User807845033 posted
I am trying to figure out how to set the headings in my gridview control using a resource file and wondering if anyone can help. I am just learning this stuff but have figured out how to use expressions and such to set this stuff up but it doesn't include access to the table headings themselves. At least not that I've seen.
Thanks
glenn
Wednesday, May 9, 2007 4:58 PM
Answers
-
User807845033 posted
Nevermind, I figured it out...
glenn
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, May 10, 2007 11:03 PM
All replies
-
User807845033 posted
just bumping to see if anyone can help me. I heard this was easy but so far not figuring it out.
Thanks,
glenn
Thursday, May 10, 2007 6:06 PM -
User807845033 posted
Nevermind, I figured it out...
glenn
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, May 10, 2007 11:03 PM -
User-999598023 posted
Can you please share your solution on the forum?
Friday, May 11, 2007 4:37 AM -
User807845033 posted
Sure:
To do a basic asp:label and localize it you would do something like this:
<asp: Label ID=lblHello runat="server" meta:resourcekey="lblHello" Text="Hello World"></asp: Label>
This is quite straight forward in that you would create a localresource file and add an entry to it that had the key of lblHello and a value of whatever you wanted. Noting that its NOT case sensitive.
When working with a grid there are a number of things exposed that I didn't at first understand, mainly because of the lack of actual explanation on the subject. But the fact is, the meta:resourcekey= line does not in fact rely at all on the ID of the field element. This simple entry just tells the control that its added to, to attempt to find anything that might be of use to it within the local resource file if it exists. If there is nothing of use then do normal stuff.
So taking a look at your grid control in source you will notice you have entries for asp: BoundFields as well as an entry in each grid for asp: CommandField. Simply adding an entry that says something like meta:resourcekey="gridcontrols" to each tag will tell the tag to go look inside the local resource to see if it can find anything related to its properties in a tag called gridcontrols. Then inside the local resouce file you'd add things like:
gridcontrols.canceltext, gridcontrols.edittext, gridcontrols.inserttext..... These entries allow you to dictate what you want the value of the Edit, Save, Delete text to be on the buttons/labels for the control.
Then supplying a fieldname entry inside each DataBound entry you can dictate what you want the headertext will be for each field by adding a tag that refers to the fieldname and then adding fieldname.headertext as an entry in the resource file. It all works quite nicely...
Oh, and for those tempted to follow all the pointers to just click the Tools / Build local resource menu on VS... Well, in a word: DON'T. I've done it a couple times to help me figure out what it was doing on test pages, but in my experience, if you do it on an actual page, especially when you've got AJAX stuff mixed in, it will replace things it shouldn't and basically screw up the formatting of your entire page. If its a simple page then it will work fine, but on more complex pages you're just asking for trouble.
glenn
Friday, May 11, 2007 6:50 AM -
User-1617887424 posted
Hi, I am trying to implement localization in a gridview. I cannot understand weel how to implement this:
Then supplying a fieldname entry inside each DataBound entry you can dictate what you want the headertext will be for each field by adding a tag that refers to the fieldname and then adding fieldname.headertext as an entry in the resource file. It all works quite nicely...
Can you write a simple example please
Monday, November 17, 2008 10:41 AM -
User1839903564 posted
hey boss
you have to finish all of your page and then go to tools menu and click generate local resources
that will generate your default resource file with all properties of the controls like Text property for lables
header & footer for gridview
and for data - in the data source you are using just include all the localized fields like for example english & arabic data fields and then include the property of DataField & sortExpression as an items with the correspondanse metkey on the resource file and make the english file is the default and after all just copy the resource file then rename it to the language desired like inde.aspx.ar-EG.resx and then translate all the items and on Datafield you have to put your Arabic datafield
Sunday, November 7, 2010 2:37 AM