When many records are displayed in the gridview, you can use the pagination function of the gridview to display these records by page. If the gridview is directly bound to the database, it is easy to: Tick the "start page.
If it is implemented using code, you need to do this:
1. Enable the pagination allowpaging attribute to true;
2. Set Some attributes in pagersetting in the property bar of the gridview to define the pagination style;
3. Bind the data to display the data on the gridview;
4. Trigger related events to display data on pages.
Some code:
1. query and bind data
1 /// <summary> 2 // query data for Data Binding 3 /// </Summary> 4 private void binddata () 5 {6 // deploy data to 7 string constr = "database information"; 8 string sqlstr = "SQL statement"; 9 sqlconnection con = new sqlconnection (constr ); 10 sqldataadapter ad = new sqldataadapter (sqlstr, con); 11 dataset DS = new dataset (); 12 ad. fill (DS); 13 gridview1.datasource = Ds; 14 gridview1.databind (); 15}
View code
2. event handling
1 /// <summary> 2 // paging event 3 /// </Summary> 4 protected void gridview1_pageindexchanging (Object sender, gridviewpageeventargs e) 5 {6 gridview1.pageindex = E. newpageindex; 7 // rebind data 8 binddata (); 9}
View code
3. Add pagination
1 /// <summary> 2 /// Add the score page to display 3 /// </Summary> 4 protected void gridview1_databound (Object sender, eventargs E) 5 {6 // Add the page to display 7 gridviewrow bottompagerrow = gridview1.bottompagerrow; 8 label bottomlabel = new label (); 9 bottomlabel. TEXT = "Current page: (" + (gridview1.pageindex + 1) + "/" + gridview1.pagecount + ")"; 10 bottompagerrow. cells [0]. controls. add (bottomlabel); 11}
View code