How To Remove An Image From The Header Text Of A RadGrid Column



TODO:

Have you ever wanted to remove an image from the Header Text of a Telerik RadGrid?

 

SOLUTION:

/// <summary>
/// Add Header Image
/// </summary>
/// <param name="TargetGrid"></param>
/// <param name="HeaderText"></param>
protected void RemoveGridHeaderImage(RadGrid TargetGrid, string HeaderText)
{
     GridHeaderItem headerItem = (GridHeaderItem)TargetGrid.MasterTableView.GetItems(GridItemType.Header)[0];
     try
     {
          headerItem[HeaderText].Controls.AddAt(1, space);
          headerItem[HeaderText].Controls.AddAt(2, img);
     }
     catch
     {
     }
}

 

NOTES:

All you have to do, is call this method in the PreRender() method of your RadGrid.  You can use this in conjunction with adding an image to a RadGrid Header at this link, which will allow you to toggle the image on and off depending on the contents of the grid.

How To Add An Image To The Header Text Of a RadGrid Column



TODO:

Have you ever wanted to add an image to the Header Text of a Telerik RadGrid?

 

SOLUTION:

/// <summary>
/// Add Header Image
/// </summary>
/// <param name="TargetGrid"></param>
/// <param name="HeaderText"></param>
/// <param name="ImageUrl"></param>
protected void AddGridHeaderImage(RadGrid TargetGrid, string HeaderText, string ImageUrl)
{
     GridHeaderItem headerItem = (GridHeaderItem)TargetGrid.MasterTableView.GetItems(GridItemType.Header)[0];
     Image img = new Image();
     Literal space = new Literal();
     space.Text = " ";
     try
     {
          img.ImageUrl = ImageUrl;
          headerItem[HeaderText].Controls.AddAt(1, space);
          headerItem[HeaderText].Controls.AddAt(2, img);
     }
     catch
     {
     }
     finally
     {
          img.Dispose();
     }
}

 

NOTES:

All you have to do, is call this method in the PreRender() method of your RadGrid.