I have a datagrid control where subheaders are created at the time on OnItemCreated event. Now they want me to show the subheaders while exporting the DataGrid to excel. I’m not sure how to proceed with.
protected void DG_Created(object sender, DataGridItemEventArgs e)
{
StringBuilder htmlHeader = new StringBuilder();
if (ListItemType.Header == e.Item.ItemType)
{
e.Item.SetRenderMethodDelegate(new RenderMethod(RenderTitle));
}
}
protected virtual void RenderTitle(HtmlTextWriter writer, Control ctl)
{
htmlWriter.AddAttribute("colspan", "15");
htmlWriter.AddAttribute("class", "subheader");
htmlWriter.RenderBeginTag("td");
htmlWriter.Write("EMPLOYEE DETAILS");
htmlWriter.RenderEndTag(); // Writes </TD>
htmlWriter.RenderEndTag(); // Writes </TR>
htmlWriter.RenderBeginTag("TR");
// Render the cells for the header row.
foreach (Control control in ctl.Controls)
{
control.RenderControl(htmlWriter);
}
}
I need to get the Rendered data table to be passed to the excels sheet along with colspan and rowspan information.
New contributor
armandrek_baba is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.