Modify the table header in the gridview (multiple layers)

Source: Internet
Author: User

Background event Functions

 

Protected   Void Gvradar_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 =   " Station No. " ;
Label L1 =   New Label ();
L1.text =   " Station No. " ;
// Because of the custom header, the sorting function originally implemented in the system becomes invalid.
// The following statements can be used to add controls to the table header and perform sorting by yourself.
TCL [ 0 ]. Controls. Add (L1 );


TCL. Add ( New Tableheadercell ());
TCL [ 1 ]. Rowspan =   2 ; // Merge Columns
TCL [ 1 ]. Text =   " Station Name " ;

TCL. Add ( New Tableheadercell ());
TCL [ 2 ]. Rowspan =   2 ; // Merge rows
TCL [ 2 ]. Text =   " Report times " ;

TCL. Add ( New Tableheadercell ());
TCL [ 3 ]. Columnspan =   2 ; // Merge Columns
TCL [ 3 ]. Text =   " Report " ;

TCL. Add ( New Tableheadercell ());
TCL [ 4 ]. Columnspan =   2 ;
TCL [ 4 ]. Text =   " Limit report " ;



TCL. Add ( New Tableheadercell ());
TCL [ 5 ]. Columnspan =   2 ;

// This section focuses on converting TCL [5] to <TH> Title 5 </Th> In the generated HTML.
// Therefore, HTML tags are injected according to this principle, which is similar to SQL injection attacks.
// TCL [5]. 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 <TH> Title 6 </Th> <TH> title 7 </Th> <TH> Title 8 <TH> Title 9 </Th> ";

TCL [ 5 ]. Text =   " False Positive </Th> </tr> <TH> site count </Th> <TH> Percentage </Th> <TH> site count </Th> <TH> Percentage </Th> <TH> count </Th> <TH> Percentage " ;


}

Foreground gridview control!

  < Div >
< ASP: gridview ID = "Gv_radar" Runat = "Server" Cssclass = "Gridviewborder" Autogeneratecolumns = "False" Onrowcreated = "Gvradar_rowcreated"   >
<% -- <Headerstyle cssclass="Gridviewheader"/> -- %>
< Rowstyle Cssclass = "Gridviewrow"   />
< Columns >
< ASP: boundfield Headertext = "Station number" Datafield = "Station number"   />
< ASP: boundfield Headertext = "Station name" Datafield = "Station name"   />
< ASP: boundfield Headertext = "" Datafield = ""   />
< ASP: boundfield Headertext = "Arrival Time" Datafield = "Arrival Time"   />
< ASP: boundfield Headertext = "Percentage to report" Datafield = "Percentage to report"   />
< ASP: boundfield Headertext = "Delayed Report times" Datafield = "Delayed Report times"   />
< ASP: boundfield Headertext = "Late percentage" Datafield = "Late percentage"   />
< ASP: boundfield Headertext = "Error reported" Datafield = "Error reported"   />
< ASP: boundfield Headertext = "Percentage of missing reports" Datafield = "Percentage of missing reports"   />
</ Columns >
< Emptydatatemplate >
< Span Style = "Color: red; text-align: center ;" > No data </ Span >
</ Emptydatatemplate >
</ ASP: gridview >
</ Div >

 

 

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.