18 May 2010

C#.Net: Dynamic Gridview Header from Resource

Share to others:
Pardon the mess.

Here is something helpful for you guys. I modified the solution that I found on the web since what I found used a different method of setting the column headers. Here is the scenario:

You have a Gridview which is populated dynamically by databinding it to a dataset and you have a resource file (we will call it fielders) which consists of the list of field names used in the dataset. The question is how you can related them to each other? Here are the steps:

Select your Gridview and look for the event RowDataBound and double click on it.
Type the following code.

if (e.Row.RowType == DataControlRowType.Header)
{
     foreach (Tablecell tc in e.Row.Cells)
     {
          tc.Text = Resources.fielders.ResourceManager.GetString(tc.Text);     }

}

Hope this helped you guys. Remeber to put this code in your Gridview's RowDataBound.

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...