3

I tried to use the following code snippet in the PreRender event to change the HeaderText but it is not working. Actually, I just noticed RadGrid1.columns was empty (with a break point) but my RadGrid has 3 columns:

protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    foreach (GridColumn col in RadGrid1.Columns)
    {
        if (col.UniqueName == "idAgir")
            col.HeaderText = "Numéro";
        if (col.UniqueName == "objet")
            col.HeaderText = "Titre du Ticket";
        if (col.UniqueName == "dateEtatIncident")
            col.HeaderText = "Date dernière intervention";
    }
    RadGrid1.Rebind(); 
}
DanM7
  • 2,203
  • 3
  • 28
  • 46

2 Answers2

8
var masterTableView = RadGrid1.MasterTableView;
var column = masterTableView.GetColumn("idAgir");
column.HeaderText = "Numéro";
masterTableView.Rebind();
Yuriy Rozhovetskiy
  • 22,270
  • 4
  • 37
  • 68
  • Thanks it works! but why mine is wrong? By the way , do you know how to change the positions of columns ? (I have a template column which displays at first position by default, i would like it at the end ) –  Feb 22 '12 at 14:09
  • @ArnaudAdigard http://www.telerik.com/help/aspnet-ajax/grid-reordering-columns.html – Yuriy Rozhovetskiy Feb 22 '12 at 14:26
0

Your way will work if you'll be using MasterTableView

protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    foreach (GridColumn col in RadGrid1.MasterTableView.Columns)
    {
        if (col.UniqueName == "idAgir")
            col.HeaderText = "Numéro";
        if (col.UniqueName == "objet")
            col.HeaderText = "Titre du Ticket";
        if (col.UniqueName == "dateEtatIncident")
            col.HeaderText = "Date dernière intervention";
    }
    RadGrid1.Rebind(); 
}
tatigo
  • 2,174
  • 1
  • 26
  • 32