The first is the stored procedure, only the data I need to take out, if the number of pages more than the total amount of data, automatically return to the last page record:
Set ANSI_NULLS on SET QUOTED_IDENTIFIER on GO--=============================================--author:clear--Descrip tion: High Performance Paging--http://www.cnblogs.com/roucheng/--============================================= Alter PROCEDURE [dbo] . [Tag_page_name_select]--The maximum number of display records and the current page number @MaxPageSize int, @PageNum int,---set an output parameter to return the total number of records for the page list use @Count int o
Utput as BEGIN SET NOCOUNT on; DECLARE--Define the sort name parameter @Name nvarchar (50),--Define the cursor position @Cursor INT--first to get the total number of records Select @Count = Count (tag_name ) from [viewdatabase0716]. [dbo].
[View_tag]; --Define where the cursor needs to begin Set @Cursor = @MaxPageSize * (@PageNum-1) +1--If the cursor is greater than the total number of records place the cursor at the beginning of the last page if @Cursor > @Count be
GIN-If the last page is equal to the maximum number of records, returns the last full page if @Count% @MaxPageSize = 0 BEGIN if @Cursor > @MaxPageSize Set @Cursor = @Count-@MaxPageSize + 1 ELSE Set @Cursor = 1 END--No Returns the remaining record of the last page ELSE Set @Cursor = @Count-(@Count% @MaxPageSize) + 1 END--pointer to the page start set Rowcount @Cursor--the position where the record begins Select @Name = tag_name from [viewdatabase0716]. [dbo].
[View_tag] OrDER by tag_name; --Set start position set Rowcount @MaxPageSize--Get the page record Select * from [viewdatabase0716]. [dbo].
[View_tag]
Where tag_name >= @Name ORDER by tag_name Set Rowcount 0 END
The
is then a paging control (...). Generate HTML code method for omitted):
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using System.Text; <summary>///Extended connection string///</summary> public class Exstringbuilder {private StringBuilder insertstring
;
Private StringBuilder pagestring;
private int privatepagenum = 1;
private int privatemaxpagesize = 25;
private int privatemaxpages = 10;
private int privatecount;
private int privateallpage;
Public Exstringbuilder () {insertstring = new StringBuilder ("");
}///<summary>//Get generated HTML///</summary> public string Gethtml {get {
return insertstring.tostring (); }}///<summary>//Get generated pagination HTML///</summary> public string Getpagehtml {g ET {return PageSTring.
ToString ();
}}///<summary>//Set or get current page///</summary> public int Pagenum {get
{return privatepagenum;
} set {if (value >= 1) {privatepagenum = value;
}}}///<summary>//Set or get the maximum number of pages///</summary> public int MaxPageSize {
get {return privatemaxpagesize;
} set {if (value >= 1) {privatemaxpagesize = value;
}}}///<summary>//Set or get maximum pages per display///</summary> public int MaxPages {
get {return privatemaxpages;
} set {privatemaxpages = value; }}///<summary>//Set or get total data///</summary> public int Datecount {get
{return privatecount;
} set {privatecount = value;
}}///<summary>////</summary> public int Allpage {get
{return privateallpage; }}///<summary>//Initialize paging///</summary> public void pagination () {Pagestri
ng = new StringBuilder ("");
Get total pages privateallpage = (int) math.ceiling ((decimal) Privatecount/(decimal) privatemaxpagesize);
Prevent superscript or subscript out of bounds if (Privatepagenum > Privateallpage) {privatepagenum = Privateallpage;
}//scrolling cursor paging mode int leftrange, Rightrange, Leftstart, rightend;
Leftrange = (privatemaxpages + 1)/2-1;
Rightrange = (privatemaxpages + 1)/2;
if (privatemaxpages >= privateallpage) {leftstart = 1;
Rightend = Privateallpage;
} else {if (privatepagenum <= leftrange) {leftstart = 1;
Rightend = Leftstart + PrivateMaxPages-1; } else if (Privateallpage-privatepagenum < Rightrange) {rightend = Privateal
Lpage;
Leftstart = rightend-privatemaxpages + 1;
} else {leftstart = Privatepagenum-leftrange;
Rightend = Privatepagenum + rightrange;
}}//Generate page Number list statistics Pagestring.append (...);
StringBuilder previousstring = new StringBuilder ("");
If on the first page if (Privatepagenum > 1) {...}
else {...}//If on the first component page if (Privatepagenum > Privatemaxpages) {
...
}
else {...}
Pagestring.append (previousstring); Generate an intermediate page http://www.cnblogs.com/roucheng/for(int i = Leftstart; I <= rightend; i++)
{//For the current page if (i = = Privatepagenum) {...}
else {...}
} StringBuilder laststring = new StringBuilder ("");
If on the last page if (Privatepagenum < Privateallpage) {...}
else {...}//If in the last group if ((Privatepagenum + privatemaxpages) < Privateallpage)
{
...
}
else {...}
Pagestring.append (laststring);
}///<summary>//Generate Tag classification form///</summary> public void tagtable (Exdatarow myexdatarow) {
Insertstring.append (...);
}
Calling Method:
Get paging settings and put in session exrequest myexrequest = new Exrequest ();
Myexrequest.pagesession ("Tag_", new string[] {"page", "Size"});
Generate tag Paging exstringbuilder tag = new Exstringbuilder ();
Sets the number of records per display tag.maxpagesize = Convert.ToInt32 (session["tag_size"]);
Sets the maximum number of pages to display tag.maxpages = 9;
Sets the current page Tag.pagenum = Convert.ToInt32 (session["Tag_page"]); string[][] Mynamenvalue = new string[2][]{new string[]{"MaxPageSize", "Pagenum", "Count"}, New Stri
Ng[]{tag.maxpagesize.tostring (), Tag.PageNum.ToString ()}};
Call stored procedure DataTable mydatatable = Mysql.batchgetdb ("Tag_page_name_select", Mynamenvalue, "Count"); Tag.datecount = (int) mysql.outputcommand.parameters["@Count"].
Value;
Tag.pagination ();
headpage.innerhtml = footpage.innerhtml = tag.getpagehtml; for (int i = 0, j = myDataTable.Rows.Count; I < J; i++) {tag.tagtable (new ExDataRow (mydatatable.rows));
} tagbox.innerhtml = tag.gethtml;
Asp. NET and MSSQL high performance paging