Webform paging query. The main understanding of this Code return _context.chinastates.skip ((nowpage-1) * numbers). Take (Numbers). ToList ();

Source: Internet
Author: User

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 ();

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.