I encountered a problem in Gridview, I cannot merge the headers if the Gridview has no record, but if the Gridview contain a record, the headers are merging.
Here is my codes that I used to merge the headers in the Gridview
protected void grdWorkExperience_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridView oGridView = (GridView)sender;
GridViewRow oGridViewRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
TableCell oTableCell = new TableCell();
oTableCell.Text = string.Empty;
oTableCell.ColumnSpan = 2;
oTableCell.BorderColor = System.Drawing.Color.White;
oGridViewRow.Cells.Add(oTableCell);
oTableCell = new TableCell();
oTableCell.Text = "Inclusive Dates(mm/dd/yyyy)";
oTableCell.ColumnSpan = 2;
oTableCell.Font.Bold = true;
oTableCell.Font.Size = 9;
oTableCell.Font.Name = "Verdana";
oTableCell.HorizontalAlign = HorizontalAlign.Center;
oTableCell.BackColor = System.Drawing.Color.FromArgb(0x33, 0x66, 0xCC);
oTableCell.ForeColor = System.Drawing.Color.White;
oTableCell.BorderColor = System.Drawing.Color.Gray;
oGridViewRow.Cells.Add(oTableCell);
oTableCell = new TableCell();
oTableCell.BorderColor = System.Drawing.Color.White;
oTableCell.ColumnSpan = 13;
oGridViewRow.Cells.Add(oTableCell);
oGridView.Controls[0].Controls.AddAt(0, oGridViewRow);
}
}
I placed that function in onRowCreated event of Gridview
What should I do to merge the Headers even if the Gridview has no record?
Move the code from
OnRowCreatedevent toLoadevent of theWindow/Control/Page