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:
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?
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?