/// <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