| Salesman |
Location |
| Beijing |
Shanghai |
Shenzhen |
| Zhang San |
100 |
200 |
300 |
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:
| Salesman |
Location |
|
|
| Beijing |
Shanghai |
Shenzhen |
| Zhang San |
100 |
200 |
300 |
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;
}
OK! It's so easy.