动态合并DataGrid表头栏位


在ItemCreate 事件中加入以下代码:

private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {

if ( e.Item.ItemType == ListItemType.Header ) {

TableCellCollection tcl = e.Item.Cells;

tcl.Clear();

tcl.Add( new TableHeaderCell() );

tcl[0].RowSpan = 2;

tcl[0].Text = "資料項目";

 

tcl.Add( new TableHeaderCell() );

tcl[1].ColumnSpan = 2;

tcl[1].Text = "會計科目</th></tr><tr><th></th><th>";

}

}

相关文章: