|
public class Splitmanager
{
public static string Aspnetpagers (Pager Pager)
{
StringBuilder sb = new StringBuilder ();
String Attr= "";
int PageCount = 0;//The total number of layers of the current page
int floorcount = Total number of layers 0;//paging
int currentlastpage = 0;//page number of the current last page
int pagenum = Pager. Recordcount/pager. PageSize + 1;//Total pages 1~24
Sb. AppendFormat ("<div class=" {0} ">n", pager. ClassName);
Attr=pager. Pageindex==1? " Disabled=disabled ":" "//Flag The current page is the first page is equal to control
The validity of the first two buttons
Sb. AppendFormat (getahtml) (attr,string. Format
(Pager. url,1), Pager. Firstpagetext));//Add the first page of code
Sb. AppendFormat (getahtml (attr, String). Format (Pager. URL, Pager. PAGEINDEX-1),
Pager. Prepagetext);//Add the previous page's code
PageCount = Pager. Pageindex/pager. maxshowpagesize;//Current Page 0~1~2
PageCount = Pager. PageIndex% Pager. Maxshowpagesize = 0? Pagecount-1:
pagecount;//clears the status of one more divisor when the current number of pages is numbered as an integer multiple pages
Floorcount = Pagenum/pager. maxshowpagesize;//number of page layers 0~1~2
Currentlastpage=pagenum<pager. Maxshowpagesize * (PageCount + 1)?
Pagenum:pager. Maxshowpagesize * (PageCount + 1);
if (pager. PageIndex > Pager. Maxshowpagesize//////When the current ordinal is greater than the number of pages per page
Again front end ...
{
Sb. AppendFormat (Getahtml ("", String. Format (Pager. Url
Pager. Maxshowpagesize * PageCount), "...");
}
for (int i = pager. Maxshowpagesize * PageCount + 1; I <= currentlastpage; i++)
{
if (i = = Pager. PageIndex)//To determine whether the loop page is the current page
{
Sb. AppendFormat (getspanhtml (i, pager). CURRENTPAGEBUTTONCSS));
}
else {
Sb. AppendFormat (Getahtml ("", String. Format (Pager. URL, i), i.tostring
()));
}
}
if (pager. PageIndex <= Pager. Maxshowpagesize * floorcount)//When the current ordinal number is less than the reciprocal
The second page page number is displayed on the back end ...
{
Sb. AppendFormat (Getahtml ("", String. Format (Pager. Url
Pager. Maxshowpagesize * (PageCount + 1) + 1), "...");
}
attr = Pager. PageIndex = = Pagenum? "Disabled=disabled": "";//Flag Current Page last
One page is equal to control the validity of the last two buttons
Sb. AppendFormat (getahtml (attr, String). Format (Pager. URL, Pager. PAGEINDEX+1),
Pager. NextPageText);//Add the next page of code
Sb. AppendFormat (getahtml (attr, String). Format (Pager. URL, Pagenum),
Pager. Lastpagetext);//Add last page code
if (pager. Showspantext)//Whether display pagination text span label display
{
Sb. AppendFormat ("<span class=") + pager. Spantextclass + "" > total {0} pages, per page
{1} Records n ", Pagenum, pager. PageSize);
Sb. AppendFormat ("to <input type=" input "id=" Jumpnum "
Style= "width:20px" name= "Jump" value= "{0}"/> page ", Pager. PageIndex = = Pagenum?
Pagenum:pager. PageIndex + 1);
Sb. AppendFormat ("<a href=" # "style=" Float:none; "
onclick= "Javascript:jump ();" > "+ pager. Submitbuttontext + "</a></span>n");
sb. Append (Getjumpscript) (pager. )//Add the JavaScript code for the button jump
}
sb. AppendFormat ("</div>");//
return sb. ToString ();
}
///<summary>
/ Get the HTML of a label
///</summary>
& nbsp; ///<param name= "title" >a ' s title</param>
///<param name= "url" >the URL of a</param>
/// <param name= "attr" >the attribute</param>
///<returns >return HTML string</returns>
private static string getahtml ( String attr,string url,string title)
{
return "<a" + attr + "href=" "+url+" "style=" margin-
right:5px; " > "+title+" </a>n ";
}
<summary>
Get the HTML of a label
</summary>
<param name= "num" >the content of Span</param>
<param name= "ClassName" >class style name</param>
<returns>return HTML String </returns>
private static string getspanhtml (int num, string className)
{
Return "<span class=" "+ ClassName +" ">" + num + "</span>n";
}
<summary>
Get the JavaScript code for jumps
</summary>
<param name= "url" > Current paging URL rule </param>
<returns> return a JavaScript code </returns>
private static string Getjumpscript (string url)
{
String scriptstr = "<script type=" Text/javascript ">n" +
"Function jump () {n" +
"Var Jnum=document.getelementbyid (" Jumpnum "). Value;n" +
"If (isNaN (jnum)) {n" +
Alert (in the Jump box, enter a number!) "); n" +
"}n" +
"Else{n" +
"Alert (jnum); n" +
"Location.href=string.format (" "+ URL +" ", jnum); n" +
"}n" +
"}n" +
"String.Format = function () {n" +
"if (Arguments.length = = 0) n" +
"Return null; N "+
"var str = arguments[0];" N "+
"For (var i=1;i<arguments.length;i++) {n" +
"var re = new RegExp (' \\{' + (i-1) + ' \} ', ' GM '); n" +
"str = str.replace (Re, arguments[i]); n" +
"}n" +
"Return Str;n" +
"}n" +
"</script>n";
return scriptstr;
}
}
|