FROM:聖哥的資訊站
在 ASP.NET 2.0 中,如果要做到如附圖的結果,只要在 GridView 的 RowCreated 事件中,自行加入新的一列 GridViewRow 就可以了,同樣的技巧也可以應用在其它的 DataControlRowType 中,例如 Footer 列。
Merge_Header.jpg | ||
檔案註解: |
| |
檔案大小: | 18.55 KB | |
檢視狀況: | 檔案被下載或檢視 858 次 | |
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
// 檢查是不是標題列
if (e.Row.RowType == DataControlRowType.Header)
{
// 建立自訂的標題
GridView gv = (GridView)sender;
GridViewRow gvRow = new
GridViewRow(0, 0, DataControlRowType.Header,
DataControlRowState.Insert);
// 增加 Department 欄位
TableCell tc1 = new TableCell();
tc1.Text = "Department";
tc1.ColumnSpan = 2; // 跨兩欄
gvRow.Cells.Add(tc1);
// 增加 Employee 欄位
TableCell tc2 = new TableCell();
tc2.Text = "Employee";
tc2.ColumnSpan = 3; // 跨三欄
gvRow.Cells.Add(tc2);
// 把這一列加到最上面
gv.Controls[0].Controls.AddAt(0, gvRow);
}
}
留言列表