Http://xml.sz.luohuedu.net/xml/ShowDetail.asp? B3F3462D-DC34-41CE-9FEE-6965B2A3D1AD
Assume that your DataGrid has three columns. Now you want to use the first two columns as "Category 1" and the third column as "Category 2". Now, you can add the following in the itemdatabound event: Code :
If (E. Item. itemtype = listitemtype. header)
{
E. Item. cells [0]. columnspan = 2;
E. item. cells [0]. TEXT = "Category 1 </TD> <TD> Category 2 </TD> </tr> <TD>" + E. item. cells [0]. text;
}
This method can be used to add any new rows.
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 display double-layer Headers
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 (maid (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