Efficient paging with ASP netpager

Source: Internet
Author: User

Efficient paging with ASP netpager
 
Paging method:

Total number of retrieved data entries: var Count = db. XXX. count (); if the previous statement has to write select count (*) from XXXX; you have to call SQLHelper. only the methods in the cs class can be used. Now we can do this in one sentence ...... Sweat ..

Use the Skip () and Take () methods for paging.

 


Note: Skip () skips the first n elements of the set; delay. That is, we will skip the given number and return the result set.

Note: Take () gets the first n elements of the set; delay. That is, only a limited number of result sets are returned.
 

Paste the code below

Aspx page code snippet: only one GridView and one AspNetPager control, no other code;

<Div>
<Asp Tutorial: GridView ID = "GridView1" runat = "server">
</Asp: GridView>
<Webdiyer: AspNetPager ID = "AspNetPager1" runat = "server" OnPageChanged = "AspNetPager1_PageChanged"
PageSize = "15" UrlPaging = "True">
</Webdiyer: AspNetPager>

</Div>


Background code:

 

Var Count = db. InBill. Count ();
AspNetPager1.RecordCount = Count;

Var paging = (from I in db. InBill
Orderby I. InDate descending
Select I). Skip (AspNetPager1.StartRecordIndex-1). Take (AspNetPager1.PageSize); // Index method: Paging operation;

GridView1.DataSource = paging;
GridView1.DataBind ();

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.