Code similar to the Baidu Google Page sharer effect (modified based on kwklover)

Source: Internet
Author: User
Tags integer division

Added: The JSON-based Ajax brushless new paging has been done, please refer to the http://www.cnblogs.com/zhouzhaokun/archive/2011/08/24/2151866.html

I was going to create a JSON-based Ajax paging effect today. When I got up early in the morning, I went to the garden to find food .. We can see the implementation of the page splitter abbreviated by kwklover. Http://www.cnblogs.com/kwklover/archive/2006/04/21/381832.html I made some modifications on his basis, but still not very perfect!CodeAs follows:

// Http://www.cnblogs.com/kwklover/archive/2006/04/21/381832.html protected void page_load (Object sender, eventargs e) {If (request ["page"] = NULL | request ["page"] = "") buildpager (10000, 1, 10); else buildpager (10000, convert. toint32 (request ["page"]), 10 );} /// <summary> /// create and display the page splitter /// </Summary> /// <Param name = "totalrecords"> total number of pages </param> /// <Param name = "currentpage"> current page number </param> /// <para M name = "pagesize"> page size </param> private void buildpager (INT totalrecords, int currentpage, int pagesize) {int alter = 4; int startpage = 1; int endpage = currentpage + alter; int totalpages = This. calculatetotalpages (totalrecords, pagesize); If (currentpage> Alter) {startpage = currentpage-alter;} If (endpage> totalpages) {endpage = totalpages ;} string strtemp = @ "<a Title = '{0}' href = 'defa Ult. aspx? Page = {1} '> {2} </a> "; stringbuilder sb = new stringbuilder (" "); If (currentpage! = Startpage) {If (currentpage> startpage) {sb. append (string. format (strtemp, 1, 1, "Homepage"); sb. append (string. format (strtemp, currentpage-1, currentpage-1, "Previous Page") ;}}for (INT I = startpage; I <= endpage; I ++) {If (currentpage = I) {sb. append ("<font color = Red>" + I + "</font>");} else {sb. append (string. format (strtemp, I, I, "[" + I + "]") ;}} if (currentpage! = Endpage) {sb. append (string. format (strtemp, currentpage + 1, currentpage + 1, "Next"); sb. append (string. format (strtemp, totalpages, totalpages, "Last page");} This. ltlshowpager. TEXT = sb. tostring ();} /*** // <summary> // calculate the total number of pages /// </Summary> /// <Param name = "totalrecords"> total number of records </Param >/// <Param name = "pagesize"> Number of records per page </param> private int calculatetotalpages (INT totalrecords, int pagesize) {int totalpagesavailable; totalpagesavailable = totalrecords/pagesize; // Since the integer division of C # rounds all the remainder to 0, therefore, you need to determine whether to add 1 If (totalrecords % pagesize)> 0) totalpagesavailable ++; return totalpagesavailable ;}
Paste the code of the page sharer first. Later I will upload a JSON-based Ajax paging... Do not spray ,:-)... Welcome

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.