Use ASP netpager for efficient Paging

Source: Internet
Author: User

I am studying LINQ recently. I think it is really very simple to see it on the page, but I am worried that I will mix up my knowledge when I learned it. I don't know if everyone is the same as me when I first learned it, because some of his landlords are really like SQL

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.

 

Reference to Li yongjing's blog

I want to learn how to blog with him: http://www.cnblogs.com/lyj/.

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

 

Related Article

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.