跨栏合并datagrid的标头栏位
今天闲着没事,在网上闲逛,找到一段适用的代码,至少对新手来说有帮助!
将datagrid的标头部分跨栏合并.只需要要在datagrid的itemcreate添加如下代码就行,呵呵!
将datagrid的标头部分跨栏合并.只需要要在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>贷";
}
}
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>贷";
}
}