ASP-page Data paging method

Source: Internet
Author: User

/// <summary>        ///Data Paging Method/// </summary>        /// <param name= "PageIndex" >Current Page</param>        /// <param name= "PageSize" >Display quantity per page</param>        /// <param name= "PageCount" >Total Data</param>        /// <param name= "Url" >links, such as: list.aspx?id=1234</param>        /// <returns></returns>         Public Static stringGetPage (intPageIndex,intPageSize,intRecordCount,stringUrl) {StringBuilder SB=NewStringBuilder (); Try            {                //Calculate Total Pages                intPageCount = RecordCount% PageSize = =0? Recordcount/pagesize:recordcount/pagesize +1; if(PageIndex <1) {PageIndex=1; }                if(PageIndex >PageCount) {PageIndex=PageCount; }                stringStarpage ="";//Home Page                stringEndPage ="";//last page                stringPrepage ="";//Previous Page                stringNextPage ="";//Next Page//links to Home and previous pages                if(PageIndex <=1|| PageCount <=1) {Starpage=""; Prepage=""; }                Else{starpage=""; Prepage="<li class=\ "previous\" ><a href=\ ""+ URL +"&page="+ (PageIndex-1) +"\ "> Prev </a></li>"; }                //links to the last and next pages                if(PageIndex = = PageCount | | PageCount <=1) {EndPage=""; NextPage=""; }                Else{endpage=""; NextPage="<li class=\ "next\" ><a href=\ ""+ URL +"&page="+ (PageIndex +1) +"\ "> Next </a></li>"; }                //page Number Output                intPagerstart =1;//first page number                if(PageCount >=5) {Pagerstart= PageIndex%5==0? PageIndex-2: Pageindex-pageindex%5; }                if(Pagerstart <1) {Pagerstart=1; }                stringNUMBTN ="";  for(inti = Pagerstart; I < Pagerstart +5&& i <= PageCount; i++)                {                    if(i = =PageIndex) {numbtn+="<li class=\ "current\" ><a>"+ i +"</a>"; }                    Else{numbtn+="<li><a href=\ ""+ URL +"&page="+ i +"\ ">"+ i +"</a></li>"; }} sb. Append (Starpage+ prepage + numbtn + NextPage +endpage); }            Catch{sb. Append (""); }            returnsb.        ToString (); }

Specific style can go to www.weixh.net reference

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.