Methods in the query
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;/// <summary>///Summary description of CARBF/// </summary> Public classcarbf{PrivateDataclassesdatacontext _context; PublicCARBF () {_context=NewDataclassesdatacontext (); } PublicList<car>Select () {return_context.car.tolist (); } PublicList<chinastates>Select1 () {return_context.chinastates.tolist (); } //Take query top five PublicList<chinastates>Select2 () {return_context.chinastates.take (5). ToList (); } //Nowpage is the current page, numbers is a page for several data. Skip is a specified number of elements in a sequence PublicList<chinastates> Select3 (intNowpage,intnumbers) { return_context.chinastates.skip (Nowpage-1) *numbers). Take (Numbers). ToList (); }}
The code in Aspx.cs.
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls; Public Partial class_default:system.web.ui.page{protected voidPage_Load (Objectsender, EventArgs e) { //list<car> List = new CARBF (). Select (); //Cache.Insert ("AAA", list); if(!IsPostBack) {bangding (1,5); } } //Click Home protected voidLinkButton1_Click (Objectsender, EventArgs e) {bangding (1,5); } Public voidBangding (intNowpage,intnumbers) {List<ChinaStates> list =NewCARBF (). SELECT3 (nowpage, numbers); Repeater1.datasource=list; Repeater1.databind (); TextBox1.Text=Nowpage. ToString (); } //Click Last protected voidLinkbutton2_click (Objectsender, EventArgs e) {List<ChinaStates> list =NewCARBF (). Select1 (); if(list. count%5==0) {bangding (list. Count/5,5); } Else if(list. count%5!=0) {bangding (list. Count/5+1,5); } } //Click on the previous page protected voidLinkbutton3_click (Objectsender, EventArgs e) { intNowpage =Convert.ToInt32 (TextBox1.Text); if(Convert.ToInt32 (TextBox1.Text) >1) {bangding (Nowpage-1,5); } Else{linkbutton3.enabled=false; } } //Click the next page protected voidLinkbutton4_click (Objectsender, EventArgs e) {List<ChinaStates> list =NewCARBF (). Select1 (); intCount = list. Count/5; if(Convert.ToInt32 (TextBox1.Text) <=count) { intNowpage =Convert.ToInt32 (TextBox1.Text); Bangding (Nowpage+1,5); } Else{linkbutton4.enabled=false; } } //When you click to go to the page protected voidLinkbutton5_click (Objectsender, EventArgs e) {List<ChinaStates> list =NewCARBF (). Select1 (); if(Convert.ToInt32 (TextBox1.Text) > list. Count/5+1) {TextBox1.Text=NULL; Literal1.text="page out of range"; } Else { intCount =Convert.ToInt32 (TextBox1.Text); Bangding (Count,5); } }}
Webform paging query. The main understanding of this Code return _context.chinastates.skip ((nowpage-1) * numbers). Take (Numbers). ToList ();