if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowIndex == 0)
{
ViewState["i"] = e.Row.RowIndex;
}
if (Convert.ToInt32(ViewState["i"].ToString()) == e.Row.RowIndex)
{
GridViewRow row = new GridViewRow(e.Row.RowIndex, 0, DataControlRowType.Header, DataControlRowState.Normal);
TableCell cell = new TableCell();
cell.BackColor = System.Drawing.Color.BurlyWood;
cell.Controls.Add(new Label { Text = "header" }); //as needed
row.Cells.Add(cell);
cell = new TableCell();
cell.Controls.Add(new Label { Text = "Name" }); //as needed
row.Cells.Add(cell);
cell = new TableCell();
cell.Controls.Add(new Label { Text = "age" }); //as needed
row.Cells.Add(cell);
cell = new TableCell();
cell.Controls.Add(new Label { Text = "Email" }); //as needed
row.Cells.Add(cell);
int cnt = Convert.ToInt32(ViewState["i"].ToString());
Table tbl = (e.Row.Parent as Table);
//tbl.Controls.AddAt(e.Row.RowIndex * cnt , row);
tbl.Controls.AddAt(e.Row.RowIndex, row);
cnt = cnt + 4;
ViewState["i"] = cnt.ToString();
}
}