Tuesday, October 8, 2013

RadGrid Tutorials - How to Change the Header Text of a RadGrid Column, When Gird is in EditMode

When you want to change the header text of a particular column in a Telerik Grid (RadGrd) you can do that easily from the code behind using the ItemCreated event in the grid.

protected void Grid_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
            //Set Grid Column Headers
            if (e.Item is GridHeaderItem)
            {
                GridHeaderItem header = (GridHeaderItem)e.Item;
                header["ColumnUniquName"].Text = "Header Titile"; 
            }
}


There may be some requirements from your client, "This column name should be changed when you are inserting an item to the grid".... So how do you do that... simple as this. 

protected void Grid_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
            //Set Grid Column Headers
            if (e.Item is GridHeaderItem)
            {
                GridHeaderItem header = (GridHeaderItem)e.Item;
              if (this.Grid.MasterTableView.IsItemInserted)
              {
                 header["ColumnUniquName"].Text = "Header Titile Changed";
              }
              else
              {
                  header["ColumnUniquName"].Text = "Header Titile";
              } 
             }
}

Hope this helps.....

No comments:

Post a Comment