简体   繁体   中英

Change RadGrid columns headers

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(); 
}
var masterTableView = RadGrid1.MasterTableView;
var column = masterTableView.GetColumn("idAgir");
column.HeaderText = "Numéro";
masterTableView.Rebind();

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM