This article describes the universal paging function implemented by ASP.net. Share to everyone for your reference, specific as follows:
Function:
1. Display 9 pages per page, more than 9 pages, 5 pages after the + 1 page display (can be arbitrarily modified)
2.CSS style can set itself
3. Without any code generation, conducive to search engine optimization
Paging Program
Objpds = new PagedDataSource ();
Objpds.datasource = dttable.defaultview;//bound data source objpds.allowpaging = true;
Objpds.pagesize =10;//paging number int curpage;
int Cshi;
int Jshi;
int zyes = Int32.Parse (objPDS.PageCount.ToString ());
This.tjixx.Text = "Total <font color=red>" + dtTable.Rows.Count + "</font> message";
This.tjixx.Text + = "| <font color=red>" + zyes + "</font> page";
if (request.querystring["page"]!= null) {if (Int32.Parse (request.querystring["page")) > Zyes) curpage = Zyes;
else Curpage = Int32.Parse (request.querystring["Page");
else {curpage = 1;} if (Zyes <= 9) {Cshi = 1;
Jshi = Zyes;
else {if (curpage <= 5) {Cshi = 1;
Jshi = 9;
else {Cshi = curPage-4;
int jshils = curpage + 4;
if (Jshils > Zyes) Jshi = Zyes;
else Jshi=curpage + 4;
} Objpds.currentpageindex = curPage-1;
StringBuilder m_strpageinfo = new StringBuilder (); for (int i = Cshi I <=jshi; i++) {if (i = = Int32.Parse (curpage. ToString ())) M_strpageinfo.append ("<span class=\" dqye\ "> <strong>" + i + "</strong> </span>
"); else M_strpageinfo.append ("<span class=\" qtye\ "> <strong> <a href=\" Newslist_ej "+ request.querystring
["Wzcat"] + "_page" + i + ". Html\" > "+ i +" </a> </strong> </span> ");
This.yemsl.Text = M_strpageinfo.tostring (); if (!objpds.isfirstpage) {linkpre.navigateurl = "Newslist_ej" + request.querystring["Wzcat"] + "_page" + Convert.ToStri
Ng (curPage-1);
Linkpre.navigateurl + = ". html"; } if (!objpds.islastpage) {linknext.navigateurl = "Newslist_ej" + request.querystring["Wzcat"] + "_page" + Convert.ToSt
Ring (Curpage + 1);
Linknext.navigateurl + = ". html";
} Linkfirstpage.navigateurl = "Newslist_ej" + request.querystring["Wzcat"] + "_page1";
Linkfirstpage.navigateurl + = ". html";
Linkendpage.navigateurl = "Newslist_ej" + request.querystring["Wzcat"] + "_page" + objPDS.PageCount.ToString (); Linkendpage.navigateurl+ = ". html"; This. Datalist4.datasource = objpds;//bound paging data this.
Datalist4.databind ();
aspx file:
Pagination section:
<div align= "center" > <asp:hyperlink id= "linkfirstpage" runat= "Server" font-underline= "False" > Home </asp :hyperlink><<
<asp:hyperlink id= "Linkpre" runat= "Server" font-underline= "False" > previous page </asp: hyperlink>
<asp:literal id= "YEMSL" runat= "Server" > </asp:Literal>
<asp:hyperlink id= " Linknext "runat=" Server font-underline= "False" > next page </asp:HyperLink>
>> <asp:hyperlink
Id= "Linkendpage" runat= "Server" font-underline= "False" > Last </asp:hyperlink>| <asp:literal
id= "Tjixx" runat= "Server" > </asp:Literal> </div>
More interested in asp.net related content readers can view the site topics: "asp.net file Operation skills Summary", "ASP.net ajax Skills Summary" and "asp.net cache operation skills Summary."
I hope this article will help you to ASP.net program design.