The multilevel table header (posted by netizens) of the DataGrid under ASP. NET is selected from the blog of yoyo83.

Source: Internet
Author: User

Multi-layer table header of the DataGrid under ASP. NET

[From: csdn]

See the following table first:

ASP. the DataGrid under net is just an htmltable, but adds a lot of attributes and methods on the basis of htmltable to be incorporated into the viewstate mechanism to generate and control it. With this understanding, it's easy to do:

We can define the column header in the property generator. It is actually just an HTML tag with "</TD> <TD>" inserted between columns; therefore, based on the example above, you can enter the following content in the header in column 3rd: </TD> </tr> <TD> Beijing </TD> <TD> Shanghai </TD> <TD> Shenzhen </TD> </tr> ", at this time, you will find that the two-layer header appears:

But it is not enough because we still need to merge rows and columns.
We can process it in the itemdatabound event of the DataGrid.

If (E. Item. itemtype = listitemtype. header)
{
E. Item. cells [0]. rowspan = 2;
E. Item. cells [1]. columnspan = 3;
E. Item. cells [2]. Visible = false;
E. Item. cells [3]. Visible = false;

Multi-layer table header of the DataGrid under ASP. NET

[From: csdn]

See the following table first:

ASP. the DataGrid under net is just an htmltable, but adds a lot of attributes and methods on the basis of htmltable to be incorporated into the viewstate mechanism to generate and control it. With this understanding, it's easy to do:

We can define the column header in the property generator. It is actually just an HTML tag with "</TD> <TD>" inserted between columns; therefore, based on the example above, you can enter the following content in the header in column 3rd: </TD> </tr> <TD> Beijing </TD> <TD> Shanghai </TD> <TD> Shenzhen </TD> </tr> ", at this time, you will find that the two-layer header appears:

But it is not enough because we still need to merge rows and columns.
We can process it in the itemdatabound event of the DataGrid.

If (E. Item. itemtype = listitemtype. header)
{
E. Item. cells [0]. rowspan = 2;
E. Item. cells [1]. columnspan = 3;
E. Item. cells [2]. Visible = false;
E. Item. cells [3]. Visible = false;

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.