I have a gridview. I have created two columns dynamically in the Row_DataBound event of the gridview.
if (e.Row.RowType == DataControlRowType.DataRow)
{
TableCell cell1 = new TableCell();
cell1.Width = 100;
e.Row.Cells.Add(cell1);
TableCell cell2 = new TableCell();
cell2.Width = 100;
e.Row.Cells.Add(cell2);
}
else
{
TableCell cell1 = new TableCell();
cell1.Width = 100;
cell1.Text = "<span style='font-weight:bold'>Total Punches";
e.Row.Cells.Add(cell1);
TableCell cell2 = new TableCell();
cell2.Width = 110;
cell2.Text = "<span style='font-weight:bold'>Hours Worked";
e.Row.Cells.Add(cell2);
}
I want to export the whole grid to Excel sheet. When I click the Export button, the last two columns which I created on Row_DataBound disappear in the excel sheet.
Can anyone help me solving this.
Thanks in Advance.
Try to move the logic to
RowCreated
event.