GridView 自定义表头

时间:2023-12-26 22:34:13

//修改表头
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
switch (e.Row.RowType)
{
case DataControlRowType.Header:

TableCellCollection tcHeader = e.Row.Cells;
tcHeader.Clear();

//第一行表头
tcHeader.Add(new TableHeaderCell());
tcHeader[0].Text = "日期";
tcHeader[0].Attributes.Add("rowspan","2");

tcHeader.Add(new TableHeaderCell());
tcHeader[1].Text = "星期";
tcHeader[1].Attributes.Add("rowspan", "2");

tcHeader.Add(new TableHeaderCell());
tcHeader[2].Text = "白班";
tcHeader[2].Attributes.Add("colspan", "2");

tcHeader.Add(new TableHeaderCell());
tcHeader[3].Text = "夜班</th></tr><tr>";
tcHeader[3].Attributes.Add("colspan", "2");

//第二行表头
tcHeader.Add(new TableHeaderCell());
tcHeader[4].Text = "姓名";

tcHeader.Add(new TableHeaderCell());
tcHeader[5].Text = "部门";

tcHeader.Add(new TableHeaderCell());
tcHeader[6].Text = "姓名";

tcHeader.Add(new TableHeaderCell());
tcHeader[7].Text = "部门";

break;
}
}