protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridViewRow rowHeader = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
Literal li = new Literal();
li.Text = @"表头文字1</th>
<th colspan='2'>表头文字2</th>
<th colspan='2'>表头文字3</th>
<th>表头文字4</th>
</tr>
<tr forecolor='" + Color.Green+ "'>";
li.Text += @"
<th >表头文字5</th>
<th >表头文字6</th>
<th colspan='2'>表头文字7</th>
<td>88888888888</td></tr>";
TableCellCollection cells = e.Row.Cells;
TableHeaderCell headerCell = new TableHeaderCell();
//下面的属性设置与 <td rowspan='2'>关键单元格</td> 要一致
headerCell.RowSpan = 2;
headerCell.Controls.Add(li);
rowHeader.Cells.Add(headerCell);
rowHeader.Cells.Add(headerCell);
rowHeader.Visible = true;
//添加到 GridView1
this.GridView1.Controls[0].Controls.AddAt(0, rowHeader);
}
}
}