以前我问过这样的问题。是对列进行操作的,实现方法是 protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
string Cells1 = "";
string Cells2 = "";
Cells1 += @"<th colspan='2'>" + "合计" + "</th>";
Cells2 += @"<th >交易台数</th><th >交易笔数</th>";
Cells1 += @"<th colspan='4'>" + "日均300笔以上" + "</th>";
Cells2 += @"<th >台数</th><th >占比</th><th >交易笔数</th><th >占比</th>";
Cells1 += @"<th colspan='4'>" + "日均200-300笔" + "</th>";
Cells2 += @"<th >台数</th><th >占比</th><th >交易笔数</th><th >占比</th>";
Cells1 += @"<th colspan='4'>" + "日均100-200笔" + "</th>";
Cells2 += @"<th >台数</th><th >占比</th><th >交易笔数</th><th >占比</th>";
Cells1 += @"<th colspan='4'>" + "日均50-100笔" + "</th>";
Cells2 += @"<th >台数</th><th >占比</th><th >交易笔数</th><th >占比</th>";
Cells1 += @"<th colspan='4'>" + "日均50笔以下" + "</th>";
Cells2 += @"<th >台数</th><th >占比</th><th >交易笔数</th><th >占比</th>"; //创建一个GridViewRow,相当于表格的 TR 一行
GridViewRow rowHeader = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
string HeaderBackColor = "#507CD1"; rowHeader.BackColor = System.Drawing.ColorTranslator.FromHtml(HeaderBackColor);
Literal newCells = new Literal();
newCells.Text = @"序号</th>
<th rowspan='2'>机构</th><th rowspan='2'>设备数</th>"
+ Cells1 + "</tr><tr bgcolor='" + HeaderBackColor + "'>";
newCells.Text += @"
" + Cells2 + "</tr><tr bgcolor='" + HeaderBackColor + "'>"; TableCellCollection cells = e.Row.Cells;
TableHeaderCell headerCell = new TableHeaderCell();
//下面的属性设置与 <td rowspan='2'>关键单元格</td> 要一致
headerCell.RowSpan = 2;
//headerCell.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
headerCell.Controls.Add(newCells);
rowHeader.Cells.Add(headerCell);
rowHeader.Visible = true;
string a = headerCell.Text;
//添加到 GridView1
GridView1.Controls[0].Controls.AddAt(0, rowHeader);
}
}现在多了对行头的操作,希望高手给解答!!!!!!!!!!!!!!!!!!!!!!!!
如下:protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
TableCellCollection tcHeader = e.Row.Cells;
tcHeader.Clear();//原有表头清空
//自己定义表头
tcHeader.Add(new TableHeaderCell());
tcHeader[0].Attributes.Add("rowspan", "2");
tcHeader[0].Text = "县(市)、区";
tcHeader[0].Width = 130;
}
}
这个方法我知道。
但是,怎么样完成对行头的操作那?就是项目下面的那些内容。
我自己可以做对列头的操作。