C # pagination code, perhaps this code is more useful than ASP. NET Paging and Aspnetpager controls

Source: Internet
Author: User

Nonsense not much to say, on the code! The following code is relatively simple, for the development of extensions, CSS has to be written by you!

        <summary>///Generate page Plugin///</summary>//<param name= "href" > Full connection </p aram>//<param name= "Queryparam" > Parameters </param>///<param Name= "pageindex" > Current page </para        m>//<param name= "pagesize" > Page solvents </param>//<param name= "Total" > Bars </param>  <returns></returns> public static string GetPages (string href, dictionary<string, object>                 Queryparam, int pageindex, int pagesize, int total) {if (pageindex <= 0 | | total = = 0) {            Return "";            } int pt = Convert.ToInt32 (math.ceiling (total * 1.00/pagesize));            if (pt = = 1) {return "";            } String querystr = ""; if (Queryparam! = null) {foreach (var item in Queryparam) {Q Uerystr + = "&" + item. Key +"=" + Item.                Value;            }} String p = "<div class= ' Pagin ' >"; p + = "<div class= ' message ' > <i class= ' Blue ' >" + Total + "</i> record, current display  <i class= ' Blue ' >" + P            Ageindex + " </i> page </div>";            p + = "<ul class= ' paginlist ' >"; if (pageindex > 1) {p + = "<li class= ' paginitem ' ><a href= '" + href + "? page=" + (PA            GEINDEX-1) + querystr + "' ><span class= ' pagepre ' ><</span></a></li>";                } if (Total/pagesize < 5)//Total number of pages not exceeding 5 {for (int i = 1; I <= pt; i++)                    {String cl = "class= ' Paginitem '";                    if (i = = pageindex) {cl = "class= ' Paginitem current '"; } p + = "<li" + Cl + "> <a href=" + href + "? page=" + i + querystr + "' >" +i + "</a></li>"; }} else//total pages more than 5 {for (int i = (pageindex-2) > 0?) (pageindex-2): pageindex; I <= ((pageindex + 3) < PT? (pageindex + 3): PT);                    i++) {String cl = "class= ' Paginitem '";                    if (i = = pageindex) {cl = "class= ' Paginitem current '"; } p + = "<li" + Cl + "> <a href=" + href + "? page=" + i + querystr + "' >" + i + "</a&                Gt;</li> "; }} if (PageIndex < PT) {p + = "<li class= ' paginitem ' ><a href = ' "+ href +"? page= "+ (pageindex + 1) + querystr +" ' ><span class= ' pagenxt ' >></span></a></l            I> ";            } p + = "</ul>";            p + = "</div>";            return p;          <div class= "Pagin" >  <div class= "message" > Total <i class= "Blue" >1256</i> record, currently showing  <i class= "Blue" >2  </i> page </div>//<ul class= "paginlist" >//<li class= "Paginitem" ><a H ref= "javascript:;" ><span class= "Pagepre" ></span></a></li>//<li class= "Paginitem" ><a href = "javascript:;" >1</a></li>//<li class= "Paginitem current" ><a href= "javascript:;" >2</a></li>//<li class= "Paginitem" ><a href= "javascript:;" >3</a></li>//<li class= "Paginitem" ><a href= "javascript:;" >4</a></li>//<li class= "Paginitem" ><a href= "javascript:;" >5</a></li>//<li class= "Paginitem more" ><a href= "javascript:;" >...</a></li>//<li class= "Paginitem" ><a href= "javascript:;" >10</a></li>//<li class= "Paginitem" ><a href= "javascript:;"        ><span class= "PAGENXT" ></span></a></li>//</ul>//</div> }

  

I welcome you to support my blog, please support my station---"Tongliang windows

C # pagination code, perhaps this code is more useful than ASP. NET Paging and Aspnetpager controls

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.