When a blank record is displayed in the gridview, the header and footer are displayed.

Source: Internet
Author: User

I haven't written anything for a while. It's also because I 've been idle for a long time. Recently, I 've got a job, and it's not a new task, then we re-design and start the unfinished work, and develop a common attribute setting for the original curve graph. Then, the common users can simply modify the Graphic Display Effect on the page, not justProgramModify it in the control of the program.

To be honest, the specific work is not very difficult. The main problem is that the interface design and program architecture design of the tool are maintained here. If this problem is not done well, there will be a lot of problems in the later expansion process, there may be a need for re-design and development. The core is because there are no experienced people in the project team to lead, so they and others are doing a lot.

The maintenance tool interface mainly uses the gridview to add, delete, modify, and display data, and all the data is saved in the XML file. The database is not used to store the data, therefore, the xml configuration file must be properly formatted.

When you see the title, you will also understand that the template column is used in the gridview.

<Itemtemplate> label used to display data controls

<Edititemtemplate> display controls when editing and saving. Select

<Footertemplate> it is used to add the displayed controls. Select

It should be clear that when there is no data, the gridview is not displayed, and only the text in emptydatatext is displayed. Many problems have been encountered during actual operations. When there is a record, the add, delete, and modify functions won't have any problems. Once there is no record, the headers and footer that were originally intended to be displayed, however, the results are not displayed, and many methods have been tried. The results are not satisfactory. For example, you can create a datatable, add an empty record, and re-fill and bind the gridview, in this way, although the header and footer are displayed, the empty record is also displayed, Because I added a column of auto-increment numbers to the gridview, and this column will display 1.

CodeAs follows:

Code

  1   Protected  Datatable getemptydatagrid ()
2 {
3 Datatable dt = New Datatable ( " Table1 " );
4 // When no data exists, it is simulated that some raw data is bound to the gridview.
5   DT = New Datatable ();
6 // DT. Columns. Add ("ID ");
7   DT. Columns. Add ( " CSMC " ); // Parameter Name
8   DT. Columns. Add ( " Csbl " ); // Parameter variables
9   DT. Columns. Add ( " Cslx " ); // Parameter type
10   DT. Columns. Add ( " Sfjl " ); // Cascade or not
11   DT. Columns. Add ( " MRZ " ); // Default Value
12 DT. Columns. Add ( " SQL " ); // SQL Filling
13 Datarow Dr = DT. newrow ();
14 DT. Rows. Add (DR );
15 DT. acceptchanges ();
16 Return DT;
17 }

 

After unremitting efforts and online materials, I finally found a solution and achieved the desired results.

In the prerender event of the gridview, judge whether rows. Count is equal to 0, and then execute the renderemptygridview function, which implements the new function.

The Code is as follows:

Code

  1   Protected     Void  Gridviewjavasprerender (  Object  Sender, eventargs E)
2 {
3 If (Gridview1.rows. Count = 0 )
4 {
5 Renderemptygridview (gridview1, " CSMC, csbl, cslx, sfjl, MRZ, SQL " );
6 }
7 }
8 Public Static Void Renderemptygridview (gridview emptygridview, String Fieldnames)
9 {
10 // Convert the gridview into only header and footer columns and hidden blank columns.
11 Datatable dtable = New Datatable ();
12 Char [] Delimiterchars = { ' , ' };
13 String [] Colname = Fieldnames. Split (delimiterchars );
14 Foreach ( String Mycol In Colname)
15 {
16 Datacolumn dcolumn = New Datacolumn (mycol. Trim ());
17 Dtable. Columns. Add (dcolumn );
18 }
19 Datarow Drow = Dtable. newrow ();
20 Foreach ( String Mycol In Colname)
21 {
22 Drow [mycol. Trim ()] = Dbnull. value;
23 }
24 Dtable. Rows. Add (Drow );
25 Emptygridview. performanceid = Null ;
26 Emptygridview. datasource = Dtable;
27 Emptygridview. databind ();
28 Emptygridview. Rows [ 0 ]. Visible = False ;
29 }

 

 

I would like to thank this person for his post: http://hi.baidu.com/fancyaj/blog/item/13ce292e05283d584fc2265c.html

If you have any other good methods, please leave a message and make progress together ~~~

 

 

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.