My ASP. NET pagination

Source: Internet
Author: User

Yes paging! I often see that N people in the garden have discussed various technologies and solutions to implement paging functions. Now I have made a few web application projects and have some experience. Next I will introduce the solution I have been using (in fact, it is simple to call the paging control ), please also point out the following points:

Also

Use the LINQ + aspnetpager paging Control

In fact, most of the work on the aspnetpager page control has been completed for you. It is indeed a very good open-source project in China! A complete demo and API are provided to facilitate the upgrade.

*. Aspx code:

Code
<! -- Register controls -->
<% @ Register Assembly = "aspnetpager" namespace = "Wuqi. webdiyer" tagprefix = "webdiyer" %>
<Asp: gridview runat = "server" enableviewstate = "false" id = "GV" width = "100%" cssclass = "listtb"
Allowsorting = "true" autogeneratecolumns = "false">
<Headerstyle Height = "13px" cssclass = "listtitle" horizontalalign = "center"/>
<Rowstyle cssclass = "TD1" horizontalalign = "center"/>
<Footerstyle Height = "2px" cssclass = "listtitle"/>
<Alternatingrowstyle cssclass = "td2" horizontalalign = "center"/>
<Columns>
<Asp: templatefield headertext = "Recommended?">
<Itemtemplate>
<% # (Bool) databinder. eval (container, "dataitem. isfeatured ")? "Yes": "no" %> </TD>
</Itemtemplate>
</ASP: templatefield>
<Asp: boundfield datafield = "addtime" headertext = "add time" dataformatstring = "{0: yyyy-mm-dd}"> </ASP: boundfield>

</Columns>
</ASP: gridview>
<! -- Pagination control -->
<Webdiyer: aspnetpager id = "pager" pagesize = "20" runat = "server" onpagechanged = "pager_pagechanged" alwaysshow = "true" urlpaging = "false"> </webdiyer: aspnetpager>

*. Aspx. CS code:

Code
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{
// Initialization
// Load data
Mydatabind (true );
}
}
Protected void pager_pagechanged (Object SRC, eventargs E)
{
// Bind the list
Mydatabind (false );
}

/// <Summary>
/// Bind data
/// </Summary>
/// <Param name = "reloadrecordcount"> whether to recalculate the total data </param>
Protected void mydatabind (bool reloadrecordcount)
{
Using (xxdatacontext VDC = new xxdatacontext (config. getinstance (). connectionstring ))
{
VaR DATA = from R in VDC. xxx
Where/* search condition, skipped here */;
// Obtain the total number of qualified records
If (reloadrecordcount)
{
Pager. recordcount = data. Count ();
}
// Pagination. It is convenient to use LINQ to read paging data.
GV. datasource = data. Skip (pager. currentpageindex-1) * pager. pagesize). Take (pager. pagesize );
GV. databind ();
}
}

It is easy to use, and aspnetpager can set whether to use Ajax effects. It can be said that its functions have met most of the requirements.

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.