Foreground HTML code:
<%@ page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%><! DOCTYPE html> Background 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{protected void Page_Load (object sender, E Ventargs e) {//Bind data each page has how many data if (! IsPostBack) {//First page loaded to Session attached value session["ys"] = 1; Testdatacontext context = new Testdatacontext (); Check the first five data of the car table skip () Skip a few, take () fetch a few//Repeater1.datasource = context. Car.skip (0). Take (5); Number of bars to be adjusted//first remove the value in session the current page minus one multiplied by five Tiaoxhuan (1); } Literal1.text = ""; } protected void button1_click (object sender, EventArgs e) {//Point previous page Remove the value from the session to int ys = Conv Ert. ToInt32 (session["Ys"]); if (Ys > 1) {testdatacontext context = new Testdatacontext (); Point up the previous page current pages minus one ys = ys-1; session["ys"] = ys; Tiaoxhuan (ys); } else {literal1.text= "<script type= ' text/javascript ' >alert (' Currently the first page ') </script>"; }} protected void Button2_Click (object sender, EventArgs e) {//Next page take out the value of the session int ys = Co Nvert. ToInt32 (session["Ys"]); Testdatacontext context = new Testdatacontext (); First judge is not the last page to remove all the number of bars minus the number of bars per page 5 See how many//int all = context. Car.count ();//The number of bars removed//int Zys; if (all% 5 = = 0)//Total pages obtained//{//Zys = ALL/5; }//else//{//Zys = ALL/5 + 1; } int Zys = Allys (); if (Ys < Zys) {ys = ys + 1; session["ys"] = ys; Tiaoxhuan (YS); } else {literal1.text = "<script type= ' text/javascript ' >alert (' Currently the last page ') </script> ;"; } } Make a function call implement jump page give a parameter jump to page public void Tiaoxhuan (int ys) {TestDataContext context = new Testdatacontext (); int qu = (ys-1) * 5; Calculates the jump to page Repeater1.datasource = context. Car.skip (QU). Take (5); Repeater1.databind (); Lable1 inside to show the current page total number of pages int all = Allys (); Label1.Text = "Current section" + Ys + "page, total:" +all+ "page"; } public int Allys ()//calculates the total number of pages {Testdatacontext context = new Testdatacontext (); int all = context. Car.count (); int Zys; if (all% 5 = = 0) {Zys = ALL/5; } else {Zys = ALL/5 + 1; } return Zys; } protected void Button3_Click (object sender, EventArgs e) {int ys = 1; try {ys = Convert.ToInt32 (TextBox1.Text); } catch (Exception) {literal1.text = "<script type= ' text/javascript ' >alert (' Please enter a number!) ') </script> "; }//Enter the number of pages to jump to how many pages//int ys = Convert.ToInt32 (TextBox1.Text); int all = Allys (); if (1 <= ys && ys <= All) {//Call jump function Tiaoxhuan (ys); Replace the values in the Session with session["ys" = ys; } else {literal1.text = "<script type= ' text/javascript ' >alert (' Out of range! ') </script> "; } }}
Page display:
WB Sub-page