protected void gv_Test_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.SetRenderMethodDelegate(new RenderMethod(NewRenderMethod));
}
}
public void NewRenderMethod(HtmlTextWriter writer, Control ctl)
{
//添加表頭第一行
writer.Write("<TD rowspan=/"2/" align=/"center/">第一二行的第一列</TD>/n");
writer.Write("<TD rowspan=/"2/" align=/"center/">第一二行的第二列</TD>/n");
writer.Write("<TD colspan=/"3/" align=/"center/">第一行第三列,跨第二行三列</TD>/n");
writer.Write("<TD colspan=/"5/" align=/"center/">第一行第四列,跨第二行五列</TD>/n");
writer.Write("<TD colspan=/"5/" align=/"center/">第一行第五列,跨第二行五列</TD>/n");
writer.Write("</TR>/n");
this.gv_WorkLoad.HeaderStyle.AddAttributesToRender(writer);
//添加表頭第二行
writer.RenderBeginTag("TR");
//因為第二行的第一第二列分別與第一行的第一第二列合并,從第三列開始添加第二行
for (int i = 2; i < ctl.Controls.Count; i++)
{
ctl.Controls[i].RenderControl(writer);
}
}