The design of the Two-layer table header and the three-layer table header of the gridview ........................

Source: Internet
Author: User

 Recently I used the gridview multi-layer header. I asked a lot of people and I felt that the answer was not very clear. In summary, I hope that the developers who will use it in the future will be able to avoid detours.


Example 1
Similar to the above situation, at first glance, I thought it was necessary to implement through the table, but I believe that the powerful gridview, so I began to look for methods. Some predecessors explained that tableheadercell is added to tablecellcollection (this should be the basic content ).

My own step is: design the structure in the table, convert double quotation marks into single quotes, and add them to tableheadercell. Text. Multiple complex DataGrid headers can be implemented.

 

1 TCL. Add ( New Tableheadercell)
2 TCL ( 1 ). Columnspan =   2
3 TCL ( 1 ). Text =   " Level1 </TD> <TD rowspan = '2'> item3 </TD> </tr> <TD> level2_1 </TD> <TD> level2_2 "

The design of the Header style is provided at the beginning <tr> <TD> and at the end </TD> </tr> by default.Therefore, if you need to set the name of the first cell (you cannot directly define columnspan through the third row in the example figure), as shown in figure 1, if the "personal Disease Risk Assessment" in the Two-line design is the first cell, you needCodeYou need to add the columnspan definition in the second line in the example figure.
Hope it will be helpful for those who will not use the gridview multi-layer header design!

Gridview Layer 2 Header


Protected void gridview1_rowcreated (Object sender, gridviewroweventargs E)
{
If (E. Row. rowtype = datacontrolrowtype. header)
{
Tablecellcollection TCL = E. Row. cells;
// Clear automatically generated Headers
TCL. Clear ();

// Add a new Header
TCL. Add (New tableheadercell ());
TCL [0]. rowspan = 2; // merge rows
TCL [0]. Text = "Title 1 ";
Label L1 = new label ();
L1.text = "Title 1 ";
// Because of the custom header, the sorting function originally implemented in the system becomes invalid.
// The following statement can add controls in the header and implement the sorting function.
TCL [0]. Controls. Add (L1 );

TCL. Add (New tableheadercell ());
TCL [1]. columnspan = 2; // merge Columns
TCL [1]. Text = "title 2 ";

TCL. Add (New tableheadercell ());
TCL [2]. rowspan = 2; // merge rows
TCL [2]. Text = "Title 3 ";

TCL. Add (New tableheadercell ());
TCL [3]. columnspan = 3; // merge Columns
TCL [3]. Text = "Title 4 ";

TCL. Add (New tableheadercell ());
TCL [4]. rowspan = 2; // The Last merged row

TCL. Add (New tableheadercell ());
TCL [5]. rowspan = 2; // The Last merged row

TCL. Add (New tableheadercell ());
TCL [6]. rowspan = 2; // The Last merged row

TCL. Add (New tableheadercell ());
TCL [7]. rowspan = 2;

TCL. add (New tableheadercell ();
TCL [8]. rowspan = 2;
// This section focuses on converting TCL [4] to Title 5
In the generated HTML. // HTML tags are injected in principle for implementation, the principle is similar to SQL injection attacks
// TCL [4]. TEXT = "Title 5 Title 2-1 Title 2-2 Title 4-1 Title 4-2 Title 4-3 Title 6 title 7 Title 8 Title 9 ";

TCL [8]. TEXT = "Title 5 </Th> </tr> <TH> Title 2-1 </Th> <TH> Title 2-2 </Th> <th> Title 4-1 </Th> <TH> Title 4-2 </Th> <TH> Title 4-3 ";

}

****************************************
Gridview three-layer Header

Protected void gridview1_rowcreated (Object sender, gridviewroweventargs E)
{
If (E. Row. rowtype = datacontrolrowtype. header)
{
Tablecellcollection TCL = E. Row. cells;
// Clear automatically generated Headers
TCL. Clear ();


// Add a new Header
TCL. Add (New tableheadercell ());
TCL [0]. columnspan = 12; // merge rows

TCL [0]. TEXT = "dddddddddddddddddddddddddddddd </tr> <TH> Title 2-1 </Th> <TH> Title 2-2 </Th> <TH> Title 4-1 </Th> <TH> Title 4-2 </Th> <TH> Title 4-3 </tr> <TH> Title 2-1 </Th> <TH> Title 2-2 ";

}

}

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.