Change RadGrid columns headers

user1173169 picture user1173169 · Feb 22, 2012 · Viewed 16.4k times · Source

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(); 
}

Answer

Yuriy Rozhovetskiy picture Yuriy Rozhovetskiy · Feb 22, 2012
var masterTableView = RadGrid1.MasterTableView;
var column = masterTableView.GetColumn("idAgir");
column.HeaderText = "Numéro";
masterTableView.Rebind();