The Aspnetpager pagination control solves many of the problems in paging, and it is easy to use this control for paging, which simplifies the tedious paging process.
The effect is as follows:
Here is the detailed code for how I use the Aspnetpager control for paging:
1. First download the latest AspNetPager.dll to www.webdiyer.com and add the reference directly to the VS2005.
2. Register the control on the page, introduce the control, and, of course, need to use a data carrier in the page, I'm using the Repeater control.
To register the paging control code:
<%@ Register assembly="aspnetpager" namespace="wuqi.webdiyer" tagprefix="webdiyer" %>
3. Pagination Control page code:
<Webdiyer:aspnetpagerID= "AspNetPager1"runat= "Server"Alwaysshow= "True"onpagechanged= "Aspnetpager1_pagechanged"PageSize= "5"Shownavigationtooltip= "True"Firstpagetext= "First page"Lastpagetext= "Last Page"NextPageText= "Next Page"Prevpagetext= "Previous page"Submitbuttontext= "Go"Textafterpageindexbox= "page"Textbeforepageindexbox= "Go to"Font-bold= "True"Font-italic= "False"font-size= "Small"Showpageindexbox= "Always"> </Webdiyer:aspnetpager>
4. Background code:
Using LINQ technology:
usingSystem;usingSystem.Collections;usingSystem.Configuration;usingSystem.Data;usingSystem.Linq;usingsystem.web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Xml.Linq;namespaceresenguang.news{ Public Partial classDefault:System.Web.UI.Page {protected voidPage_Load (Objectsender, EventArgs e) { if(!IsPostBack) {initnews (); } } Private voidinitnews () {entitydbdatacontext DC=NewEntitydbdatacontext (); intpage = This. Aspnetpager1.currentpageindex; intSize = This. Aspnetpager1.pagesize; varNewslist = Dc.t_news. OrderByDescending (p =p.id). ToList (); varNews = Newslist.skip (Size * (Page-1)). Take (size). ToList (); if(News! =NULL&& News. Count >0) {Aspnetpager1.recordcount=Newslist.count; Newsdl.datasource=News; Newsdl.databind (); } Else{Aspnetpager1.recordcount=0; Newsdl.datasource=NULL; Newsdl.databind (); } } protected voidAspnetpager1_pagechanged (Objectsender, EventArgs e) {initnews (); } }}