Method One hyperlink
Default.aspx.cs HTML code *************************************************************************************
<%@ page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%><! DOCTYPE html>
C # code *************************************************************************************
Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.UI;using System.web.ui.webcontrols;public partial class _default:system.web.ui.page{private Mydbdatacontext _Context = new Mydbdatacontext ();p rivate const int PAGESIZE = 3;private int _pageno = 1; Current page number//Get total pages public int Getpagecount () {//Fetch total number of rows int rowscount = _context.car.count ();//Calculates the sum of pages int pagecount = (int) Math.ceiling (1.0*rowscount/pagesize); return PageCount;} Public list<car> Getpagedcar () {var query = _context.car.skip (pagesize* (_pageno-1)). Take (PAGESIZE); return query. ToList ();} protected void Page_Load (object sender, EventArgs e)//Load page {if (! IsPostBack) {if (request["pn"]! = null) {_pageno = Convert.ToInt32 (request["PN"]);} Repeater1.datasource = Getpagedcar (); Repeater1.databind (); if (_pageno = = 1)//If it is the first page {lnkprev.href = "default.aspx?pn=1";//link to the first page}else{lnkprev.href = " Default.aspx?pn= "+ (_pageno-1). ToString ();//If it is not -1}if (_pageno = = Getpagecount ())//The next page equals the obtained page {lnknext.href = "Default.aspx?pn= "+ getpagecount (). ToString ();} Else{lnknext.href = "default.aspx?pn=" + (_pageno + 1). ToString ();//Otherwise +1}}}Default2.aspx.cs HTML code *************************************************************************************
<%@ page language= "C #" autoeventwireup= "true" codefile= "Default2.aspx.cs" inherits= "DEFAULT2"%><! DOCTYPE html>C # code *************************************************************************************
Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.UI;using System.web.ui.webcontrols;public partial class default2:system.web.ui.page{private Mydbdatacontext _Context = new Mydbdatacontext ();p rivate const int PAGESIZE = 3;private int _pageno = 1; Current page number//Get total pages public int Getpagecount () {//Fetch total number of rows int rowscount = _context.car.count ();//Calculates the sum of pages int pagecount = (int) Math.ceiling (1.0 * rowscount/pagesize); return PageCount;} Public list<car> Getpagedcar () {_pageno = Convert.ToInt32 (pagelist.selectedvalue); var query = _context.car.skip ( PAGESIZE * (_pageno-1)). Take (PAGESIZE); return query. ToList ();} protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {fillpagelist (); Showcars ();}} private void Showcars () {repeater1.datasource = Getpagedcar (); Repeater1.databind ();//Assign values to the current page and a total of lblnow.text = Pagelist.selectedvalue;lblall.text = PageList.Items.Count.ToString ();} private void Fillpagelist () {PageList.Items.Clear (); int pagecount = GetPageCount (); for (int i = 1; I <= PageCount; i++) {ListItem li = new ListItem (i.ToString (), i.tostring ()); PageList.Items.Add (li);}} protected void Pagelist_selectedindexchanged (object sender, EventArgs e) {showcars ();} protected void Button1_Click (object sender, EventArgs e) {if (Pagelist.selectedindex = = 0) {return;} pagelist.selectedindex--; Showcars ();} protected void button2_click (object sender, EventArgs e) {if (Pagelist.selectedindex = = Getpagecount ()-1) {return;} pagelist.selectedindex++; Showcars ();}}Web previous page next page with hyperlink button