The header is displayed when the gridview record is empty.

Source: Internet
Author: User

Address: http://www.star1168.com/blog/index.php/archives/158

 

   Public   Class Gridviewex: gridview { // Used to save Columns      Private Arraylist _ columns; [defaultvalue ( True )] Public   Bool Forceshowheader { Get { Object O = viewstate [" Forceshowheader "]; If (O! = Null ) Return ( Bool ) O; Return   True ;} Set {Viewstate [" Forceshowheader "] = Value ;}} Protected   Override Icollection createcolumns (pageddatasource datasource, Bool Usedatasource ){ If (_ Columns! = Null ) Return _ Columns; _ columns = (arraylist) Base . Createcolumns (datasource, usedatasource ); Return _ Columns ;} Protected   Override   Int Createchildcontrols (ienumerable datasource, Bool Databinding ){Int Count = Base . Createchildcontrols (datasource, databinding ); If (Forceshowheader & COUNT = 0) {table; If (Controls. Count = 0) {table = createchildtable (); controls. Add (table );} Else {Table = controls [0] As Table; If (Table = Null ) Throw  New Applicationexception (" The first child control is not a table control. ");} Datacontrolfield [] fields = New Datacontrolfield [_ columns. Count]; _ columns. copyto (fields, 0 ); // Create a header and initialize this line Gridviewrow headerrow = createrow (-1,-1, datacontrolrowtype. header, datacontrolrowstate. Normal); initializerow (headerrow, fields ); // Raise the rowcreated event Gridviewroweventargs ARGs = New Gridviewroweventargs (headerrow); onrowcreated (ARGs ); // Add the header row to the table Table. Rows. addat (0, headerrow );} Return Count ;}}

 
 

Set the forceshowheader attribute to true (the default value is true ).

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.