It's useful to do Web sites that don't use JS UI controls.
Usage:
var ps=new pagestring ();
/* Optional Parameters *
PS. Setisenglish = true;//is in English (default: false)
PS. Setisshowtext = true;//Whether to display pagination text (default: TRUE)
//ps. Textformat= "" (default: Span class=\ "pagetext\" "strong" in total "/strong": {0} article "strong" The current "/strong": {1}/{2} "/span")
//ps. Setpageindexname request["PageIndex" (Default value: "PageIndex")
PS. Setisajax = false;// (default: "false")//
* function parameter/
int total = 10000;
int pageSize = ten;
int pageIndex = Convert.ToInt32 (request["PageIndex"]);
var page = Ps. ToString (Total, pageSize, PageIndex, "/ui/pagestringtest.aspx");
Gets the page HTML output
Response.Write (page);
Effect:
Code:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Text.RegularExpressions; namespace Syntacticsugar {///<summary>///* * Description: Pagination class///* * Founder Time: 2015-5-29///* * Modified time:-///* * Author: Sunka Ixuan public class Pagestring {///<summary>///is English (default: false)///</summary> public
BOOL Setisenglish {get; set;}
<summary>///display pagination text (default: TRUE)///</summary> public bool Setisshowtext {get; set;} <summary>///Style (default: "Pagination")///</summary> public string Setclassname {get; set; ///<summary>///Paging parameter name (default: "PageIndex")///</summary> public string Setpageindexname {g Et Set ///<summary>///is asynchronous synchronous href= ' asynchronous Onclick=ajaxpage () (default: false)///</summary> public B
Ool Setisajax {get; set;} <summary>///Custom Text///string. Format ("{0}{1}{2} ", Total records, current page number, total pages"///default value: Span class=\ "pagetext\" "strong" a total of "/strong": {0} "strong" Current "/strong": {1}/{2} "/
Span///</summary> public string Settextformat {get; set;}
Public pagestring () {setisenglish = false;
Setisshowtext = true; Settextformat = "<span class=\" pagetext\ "><strong> Total </strong>:{0} bars <strong> current </strong
>:{1}/{2}</span> ";
Setclassname = "pagination";
Setpageindexname = "PageIndex";
Setisajax = false; }/* Free style. Pagination. Click {cursor:pointer}. Pagination a{text-decoration:none;border:1px solid #AAE col
Or: #15B; font-size:13px;border-radius:2px;}
Pagination span{color: #666; font-size:13px;display:inline-block;border:1px solid #ccc;p adding:0.2em 0.6em;
. Pagination span.pagetext{Border:none}. Pagination A:hover{background: #26B; color: #fff;}
. pagination A{display:inline-block;padding:0.2em 0.6em; . Pagination. Page_Current{background: #26B; color: #fff; border:1px solid #AAE; margin-right:5px;}
. pagination{margin-top:20px;}
. Pagination. Current.prev, pagination. Current.next{color: #999; Border-color: #999; background: #fff;} * *////<summary>///pagination algorithm [a] total 20 pages First Prev 1 2 3 4 5 6 7 8 9 10 Next last///</summary>/// ;p Aram Name= "Total" > record number </param>///<param name= "pageSize" > per page record </param>///<param name= "PageIndex" > Current page </param>///<param name= "query_string" >url parameters </param>///<returns>< /returns> public string ToString (int total, int pageSize, int pageIndex, string query_string) {int all
page = 0;
int next = 0;
int pre = 0;
int startcount = 0;
int endcount = 0;
StringBuilder pagestr = new StringBuilder (); PageIndex = PageIndex = = 0?
1:pageindex; Pagestr.
AppendFormat ("<div class=\" {0}\ ">", Setclassname); if (PagEindex < 1) {pageIndex = 1;}
Calculates the total number of pages if (pageSize!= 0) {allpage = (total/pagesize);
Allpage = (total% pageSize)!= 0? allpage + 1:allpage);
Allpage = (Allpage = = 0 1:allpage);
Next = PageIndex + 1;
Pre = PageIndex-1; Startcount = (PageIndex + 5) > Allpage? Allpage-9: pageindex-4;//Middle Page starting serial number//middle page terminating serial number Endcount = PageIndex < 5?
10:pageindex + 5; if (Startcount < 1) {startcount = 1;}//To avoid negative output, set if less than 1 starts with ordinal 1 if (Allpage < endcount) {Endcount = Al Lpage;
}//page number +5 will produce the final output sequence number greater than the total page number, then it is necessary to control the number of pages within the page bool Isfirst = PageIndex = 1;
BOOL Islast = PageIndex = = Allpage; if (Setisshowtext) pagestr.
AppendFormat (Settextformat, Total, PageIndex, allpage); if (Isfirst) {pagestr.
Append ("<span> home </span> <span> prev </span>"); else {pagestr. AppendFormat ("<a href=\" {0}pageindex=1\ "> Home </a> <a href=\" {0}pageindex={1}\ "> Page </a>", query_string, pre); }//middle page processing, which adds time complexity, reduces space complexity for (int i = Startcount i <= endcount; i++) {bool Iscurent = PA
Geindex = i; if (iscurent) {pagestr.
Append ("<a class=\" page_current\ ">" + i + "</a>"); else {pagestr.
Append ("<a href=\" "+ query_string +" pageindex= "+ i +" \ ">" + i + "</a>"); } if (Islast) {pagestr.
Append ("<span> next </span> <span> last page </span>"); else {pagestr. Append ("<a href=\" "+ query_string +" pageindex= "+ next +" \ "> next page </a> <a href=\" "+ query_string +" Pagei
ndex= "+ allpage +" \ "> Last </a>"); } pagestr.
AppendFormat ("</div>"); Return Conversiondata (pagestr.
ToString ());
private string Conversiondata (String page) { if (setisenglish) {page= page. Replace ("prev", "Previous"). Replace ("Next page", "Next"). Replace ("All", "total"). Replace ("Current", "present"). Replace ("Bar", "records"). Replace ("Home", "first").
Replace ("End", "last");
} if (Setisajax) {var matches = regex.matches (page, @ "href\=" ". *?" "", Regexoptions.singleline); if (matches!= null && matches. Count > 0) {foreach (Match m in matches) {page = page. Replace (M.value, String. Format ("class=\" Click\ "onclick=\" Ajaxpage (' {0} ') \ ", Regex.match (M.value, String.) Format (@ "{0}\= (\d+)", Setpageindexname)). GROUPS[1].
Value));
}} return page;
}
}
}