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