Web previous page next page with hyperlink button

Source: Internet
Author: User

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

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.