This is a migrated thread and some comments may be shown as answers.

Add Additional Header Row To Grid

1 Answer 546 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jimmy Hill
Top achievements
Rank 1
Jimmy Hill asked on 22 Aug 2011, 01:26 PM
I'm using Jason Maronge's code found here: http://www.telerik.com/community/forums/aspnet-ajax/grid/adding-multiple-header-rows-at-runtime-in-radgrid.aspx to add an additional header row to my grid. Here's my code:

void rgItemSummary_PreRender(object sender, EventArgs e)
    {
        //get the current header
        GridItem[] header = rgItemSummary.MasterTableView.GetItems(GridItemType.Header);
  
        //get the current THead element
        GridTHead head = ((GridTHead)header[0].Parent.Controls[0].Parent);
  
        //Get the GridHeaderItem from the THead
        GridHeaderItem currentHeaderItem = (GridHeaderItem)head.Controls[0];
  
        //Clear all GridHeaderItems
        head.Controls.Clear();
  
        //create a new GridHeaderItem which will be the new row
        GridHeaderItem newHeaderItem = new GridHeaderItem(rgItemSummary.MasterTableView, 0, 0);
  
        //Active column header
        GridTableHeaderCell itemInfoCell = new GridTableHeaderCell()
        {
            Text = "Item Info",
            ColumnSpan = 3,
            HorizontalAlign = HorizontalAlign.Center
        };
  
        //Period Data Header
        GridTableHeaderCell periodCell = new GridTableHeaderCell()
        {
            Text = "Period Data",
            ColumnSpan = 3,
            HorizontalAlign = HorizontalAlign.Center
        };
  
        //Current Available Header
        GridTableHeaderCell currentAvailableCell = new GridTableHeaderCell()
        {
            Text = "Current Available",
            ColumnSpan = 3,
            HorizontalAlign = HorizontalAlign.Center
        };
  
        newHeaderItem.Cells.Add(itemInfoCell);
        newHeaderItem.Cells.Add(periodCell);
        newHeaderItem.Cells.Add(currentAvailableCell);
  
        //Add back the GridHeaderItems in the order you want them to appear
        head.Controls.Add(newHeaderItem);
        head.Controls.Add(currentHeaderItem);
    }
 
Here's the problem: Only the "Current Available" cell is showing up. Any ideas what I'm doing wrong here?

EDIT: Assuming that the grid was only accepting the last cell that I added, I commented out newHeaderItem.Cells.Add(currentAvailableCell);. Oddly enough, that removed the Current Available but the other cells still were not added. When I step through the code, I can see that after newHeaderItem.Cells.Add(currentAvailableCell); is executed, the newHeaderItem object contains three controls. Why is only one being rendered?

1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 25 Aug 2011, 08:24 AM
Hi Jimmy Hill,

The only supported approach for having multiple header rows is currently using RadGrid's GridTemplateColumn (you can note the demo shows a 2-row header above the template column).

Kind regards,
Pavlina
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
Grid
Asked by
Jimmy Hill
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or