int pageSize = 0; Number of rows per page int nMax = 0; Total number of records int pagecount = 0; Number of pages = Total Records/pages per page int pagecurrent = 0; Current page number int ncurrent = 0; The current record line private void Bind () {//td = Um.dataall (); PageSize = 30; Set number of page lines NMax = TD. Rows.Count; PageCount = (nmax/pagesize); Calculates the total number of pages if ((nMax% pageSize) > 0) pagecount++; Pagecurrent = 1; The current number of pages starts from 1 ncurrent = 0; The current number of records starts at 0 loaddata (); }private void LoadData () {int nstartpos = 0; The current page starts recording line int nendpos = 0; Current page end record line DataTable dttemp = TD. Clone (); Clone the DataTable Structure Framework if (pagecurrent = = PageCount) {nendpos = NMax; } else {nendpos = pageSize * pagecurrent; } Nstartpos = Ncurrent; Lblpagecount.text = "Total" + pageCount.tostring () + "page"; Txtcurrentpage.text = convert.tostring (pagecurrent); Copy the record line from the metadata source if (TD. Rows.Count > 0) {for (int i = Nstartpos; i < Nendpos; i++) { Dttemp.importrow (TD. Rows[i]); ncurrent++; }} datagridview1.datasource = Dttemp; DataGridView the line int ENDC = TD is not selected by default. Rows.Count; if (Endc > PageSize * pagecurrent) ENDC = pageSize * pagecurrent; int k = 0; for (int i = pageSize * (pageCurrent-1) + 1; I <= ENDC; i++) {datagridview1.rows[k]. Headercell.value = i.ToString (); k++; }}private void Up_click (object sender, EventArgs e) {pagecurrent--; if (pagecurrent <= 0) {MessageBox.Show ("is already the first page,Please click on "Next Page" to view! "); Return } else {ncurrent = PageSize * (pageCurrent-1); } loaddata (); } private void Down_click (object sender, EventArgs e) {pagecurrent++; if (Pagecurrent > PageCount) {MessageBox.Show ("is already the last page, please click on" Previous "to view!) "); Return } else {ncurrent = PageSize * (pageCurrent-1); } loaddata (); } private void First_click (object sender, EventArgs e) {pagecurrent = 1; Ncurrent = PageSize * (pageCurrent-1); LoadData (); } private void End_click (object sender, EventArgs e) {pagecurrent = PageCount; Ncurrent = PageSize * (pageCurrent-1); LoadData (); private void Skip_click (object sender, EventArgs e) {iNT CURRENTP = Convert.ToInt32 (txtCurrentPage.Text.ToString ()); if (Currentp > PageCount) {MessageBox.Show ("more than the maximum number of pages, please reenter"); Return } else {pagecurrent = CURRENTP; Ncurrent = PageSize * (pageCurrent-1); LoadData (); } }
C # page Flip design: Home, Prev, Next, last, jump