Friday, October 10, 2008

Radgrid Column Name Changing

At work I ran into a scenario where we couldn't use our customized Radgrid which handles localization behind the scenes. So I had to use the standard Telerik Radgrid. Here is a link to how to deal with columns-

http://www.telerik.com/help/aspnet/grid/grdusingcolumns.html

For some reason changing the header text as suggested in the example for me didn't work. I need to change the header text names at runtime due to the headers need to be translated into the viewing clients language. But in fooling around I found a neat trick that did work. It might not be too efficient, but it got what I wanted to get done done.

My Radgrid was bound to a sqldatasource. So I added a new selected event handler on the Page.Init like so-


protected void Page_Init (object sender, EventArgs e)
{
myDataSet.Selected +=
new SqlDataSourceStatusEventHandler (myDataSet_Selected);
}
void myDataSet_Selected (object sender, SqlDataSourceStatusEventArgs e)
{
foreach (GridColumn column in myGridView.Columns)
{
if (column.UniqueName == "some name" )
{
(column
as GridBoundColumn ).HeaderText =
"whatever the translated text is";
break;
}
}
}


It works! Hope this helps someone.

No comments: