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.