asp.net implementation of universal paging function _ Practical skills

Source: Internet
Author: User

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.

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.