This is a migrated thread and some comments may be shown as answers.

How To rename Column in Grid where AutoGenerateColumns=True

3 Answers 470 Views
Grid
This is a migrated thread and some comments may be shown as answers.
johnson lim
Top achievements
Rank 1
johnson lim asked on 12 Jan 2012, 09:16 AM
HI,
I have a grid that serves multi purpose. The data pass to the grid is dynamic. And hence i set AutoGenerateColumns="True"
I need to change the column header text to different different text in  different situation based on column index.
All the resources found online manage to change the header text of a particular column based on column Unique name.

Does anyone has idea on this?
Help Please!!

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 12 Jan 2012, 09:20 AM
Hello Johnson,

protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        foreach (GridColumn column in RadGrid1.MasterTableView.AutoGeneratedColumns)
        {
            if (column.OrderIndex == 1)
            {
                column.HeaderText = "Your Text";
            }
        }
    }


Thanks,
Jayesh Goyani
0
johnson lim
Top achievements
Rank 1
answered on 12 Jan 2012, 09:26 AM
Hi Jayesh, is it possible to set it in  ItemDataBound event?
 I had already use NeedDataSource event.
The use of PreRender event seems not pratical, because this event will be execute whenever there is a post back.
0
Tsvetina
Telerik team
answered on 12 Jan 2012, 12:44 PM
Hi Johnson,

You can try using ItemDataBound with a check if(e.Item is GridHeaderItem). However, the control rendered there depends on whether you have sorting enabled, so you should have this in mind when accessing it.

Also, you could use the ColumnCreated server event. It fires for each autogenerated column and you could modify the column properties there.

For more information on working with autogenerated columns, see this link:
http://www.telerik.com/help/aspnet-ajax/grid-customizing-autogenerated-columns.html

Kind regards,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
johnson lim
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
johnson lim
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or