[Post] The DataGrid displays dual-layer headers to merge cells.

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.