This is the front-end code of the gridview page.
Allowpaging = "true" whether automatic Paging
Pagesize = "10" after 10 data entries
Autogeneratecolumns = "false" cancel the built-in table mode
Onpageindexchanging = "gvwdesignationname_pageindexchanging"PageindexchangingEvent.
When more than 10 pieces of data are automatically paged, the <pagertemplate> </pagertemplate> Control in the gridview is displayed.
The gvwdesignationname_pageindexchanging event is to obtain the Foreground Data, assign the value to the corresponding gridview attribute, and re-bind the data to jump to the corresponding page number.
<HTML xmlns = "http://www.w3.org/1999/xhtml">
This is the background code
Using System; using System. collections. generic; using System. linq; using System. web; using System. web. UI; using System. web. UI. webControls; namespace test2 {public partial class WebForm1: System. web. UI. page {protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {BinData () ;}// bind private void BinData () {Exam a = new Exam (); GridView1.DataSource =. listExam (); GridView1.DataBind ();} // pagination protected void handle (object sender, GridViewPageEventArgs e) {// you can get the control GridView theGrid = sender as GridView; int newPageIndex = 0; if (e. newPageIndex =-3) {// click the Go button TextBox txtNewPageIndex = null; // compared with the DataGrid, The GridView provides For more APIs, you can use BottomPagerRow or TopPagerRow to retrieve paging blocks. Of course, HeaderRow and FooterRow GridViewRow pagerRow = theGrid. BottomPagerRow; if (pagerRow! = Null) {// obtain the text control txtNewPageIndex = pagerRow. FindControl ("txtNewPageIndex") as TextBox;} if (txtNewPageIndex! = Null) {// obtain the index newPageIndex = int. parse (txtNewPageIndex. text)-1 ;}} else {// click another button newPageIndex = e. newPageIndex;} // prevents the new index from overflowing with newPageIndex = newPageIndex <0? 0: newPageIndex; newPageIndex = newPageIndex> = theGrid. PageCount? TheGrid. PageCount-1: newPageIndex; // get the new value theGrid. PageIndex = newPageIndex; // BinData ();}}}
This is the code paging Effect