http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=B3F3462D-DC34-41CE-9FEE-6965B2A3D1AD
假設你的DataGrid有三列,現在想將前兩列作為"大類1",第三列作為"大類2",現在,你可以在ItemDataBound事件中加入下面的程式碼:
if (e.Item.ItemType == ListItemType.Header)
{
e.Item.Cells[0].ColumnSpan = 2;
e.Item.Cells[0].Text = "大類1</td><td>大類2</td></tr><tr><td>" + e.Item.Cells[0].Text;
}
用這個方法可以為任意新增新行。
C#
if (e.Item.ItemType == ListItemType.Header)
{
DataGridItem dgi = new DataGridItem(0,-1,ListItemType.Header);
DataGridItem dgi1= new DataGridItem(0,-1,ListItemType.Header);
Table tb = new Table();
tb = (Table)DataGrid1.Controls[0];
tb.Rows.AddAt(0,dgi);
tb.Rows.AddAt(1,dgi1);
TableCell tc = new TableCell();
TableCell tc1 = new TableCell();
TableCell tc2 = new TableCell();
TableCell tc22 = new TableCell();
tc.Text = "ddd";
tc.ColumnSpan = 1;
dgi.Cells.Add(tc);
tc1.Text = "ddd2";
tc1.ColumnSpan = 1;
dgi.Cells.Add(tc1);
tc2.Text = "ddd";
tc2.ColumnSpan = 1;
dgi1.Cells.Add(tc2);
tc22.Text = "ddd2";
tc22.ColumnSpan = 1;
dgi1.Cells.Add(tc22);
}
VB.NET顯示雙層表頭
Dim dgi As DataGridItem
Dim dgi1 As DataGridItem
Dim tc As New TableCell()
Dim tc1 As New TableCell()
Dim tc2 As New TableCell()
Dim tc22 As New TableCell()
Dim tb As New Table()
If (e.Item.ItemType = ListItemType.Header) Then
dgi = New DataGridItem(0, -1, ListItemType.Header)
dgi1 = New DataGridItem(0, -1, ListItemType.Header)
tb = CType(DataGrid1.Controls(0), Table)
tb.Rows.AddAt(0, dgi)
tb.Rows.AddAt(1, dgi1)
tc.Text = "ddd"
tc.ColumnSpan = 1
dgi.Cells.Add(tc)
tc1.Text = "ddd2"
tc1.ColumnSpan = 1
dgi.Cells.Add(tc1)
tc2.Text = "ddd"
tc2.ColumnSpan = 1
dgi1.Cells.Add(tc2)
tc22.Text = "ddd2"
tc22.ColumnSpan = 1
dgi1.Cells.Add(tc22)
End If
[轉帖]DataGrid顯示雙層表頭,即可實現合併單元格問題
相關文章
- 【專案實戰】---EasyUI DataGrid單元格合併UI
- js實現table合併相同列單元格JS
- el-table自定義合併單元格後,單元格錯亂的問題
- Html合併單元格HTML
- 各位推薦一下,哪種報表可以實現凍結表頭合併單元格,謝謝!
- WPF DataGrid實現單擊單元格直接編輯
- Java Servlet 實現合併多單元格匯出ExcelJavaServletExcel
- vue表格合併單元格Vue
- EasyExcel-合併單元格Excel
- js 表格合併單元格JS
- Html Table 合併單元格HTML
- GridView合併單元格View
- PowerBuilder---合併相同單元格UI
- 自定義的單元格合併
- Bootstrap-table 合併相同單元格boot
- excel合併的單元格重新填充Excel
- [安卓] 16、ListView和GridView結合顯示單元實現自定義列表顯示效果安卓View
- 關於HTML表格合併單元格的靈魂拷問HTML
- postgresql高階應用之合併單元格SQL
- td單元格合併程式碼例項
- Excel合併單元格的兩種簡單方法Excel
- Silverlight DataGrid 多重表頭實現
- elementui表格動態資料單元格合併UI
- elementui——表格的相同內容單元格合併UI
- table表格單元格合併程式碼例項
- JS動態生成表格後 合併單元格JS
- Excel合併單元格資料的方法教程Excel
- 關於Easyui的datagrid的可編輯單元格和合並單元格UI
- C#中實現DataGrid雙向排序(轉)C#排序
- Geoserver + MySQL實現圖層顯示和文字顯示ServerMySql
- table表格單元格橫向和屬性合併
- 用CSS樣式實現顯示隱藏層 (轉)CSS
- EasyUI DataGrid 單元格編輯 註釋版UI
- NPOI擴充套件--判斷指定單元格是否為合併單元格和輸出該單元格的行列跨度(維度)套件
- JavaScript合併表格中的內容相同的單元格JavaScript
- Unity網格合併_材質合併[轉]Unity
- GridView多行表頭合併View
- excel合併單元格快捷鍵 excel多個表格內容合併到一起Excel