public MergeGridviewHeader() { MergedColumns.Clear(); StartColumns.Clear(); Titles.Clear(); MergedColumnCss.Clear(); }
public static void RenderHeader(HtmlTextWriter output, Control container) { for (int i = 0; i < container.Controls.Count; i++) { TableCell cell = (TableCell)container.Controls[i]; //stretch non merged columns for two rows if (!MergedColumns.Contains(i)) { cell.Attributes["rowspan"] = "2"; cell.RenderControl(output); } else //render merged columns common title if (StartColumns.Contains(i)) { if (MergedColumnCss.ContainsKey(i)) { output.Write(string.Format("<th align='center' colspan='{0}' class='{2}' >{1}</th>", StartColumns[i], Titles[i], MergedColumnCss[i])); } else { output.Write(string.Format("<th align='center' colspan='{0}' >{1}</th>", StartColumns[i], Titles[i])); } } } //close the first row output.RenderEndTag(); //set attributes for the second row //grid.HeaderStyle.AddAttributesToRender(output); //start the second row output.RenderBeginTag("tr"); //render the second row (only the merged columns) int currentCssID = 0; for (int i = 0; i < MergedColumns.Count; i++) { TableCell cell = (TableCell)container.Controls[MergedColumns[i]]; if (MergedColumnCss.ContainsKey(MergedColumns[i])) { currentCssID = MergedColumns[i]; } if (MergedColumnCss.ContainsKey(currentCssID)) { cell.CssClass = MergedColumnCss[currentCssID]; } cell.RenderControl(output); } MergedColumns.Clear(); StartColumns.Clear(); Titles.Clear(); MergedColumnCss.Clear(); }