標題1 | 標題2 | |
---|---|---|
子標題1 | 子標題2 | |
在.net中可用如下的方法實現跨行合併DataGrid表頭欄位:在DataGrid 的ItemCreate 事件中加入以下代碼。
{
if ( e.Item.ItemType == ListItemType.Header )
{
TableCellCollection tcl = e.Item.Cells;//獲得表頭元素的實例
tcl.Clear();//清除原有控件
tcl.Add( new TableHeaderCell() );//添加表頭控件
tcl[0].RowSpan = 2; //定義表頭的所佔的行數
tcl[0].Text = "標題1";
//下一行
tcl.Add( new TableHeaderCell() );
tcl[1].ColumnSpan = 2;
tcl[1].Text = "標題2
}
}