Recently to the page to kill, remember before the change DW ASP pagination method, and later wrote the hand-crafted ASP paging, now enter. NET, of course, with stored procedures to create pure manual high-performance paging.
Why it is called high-performance, why should be handmade, not used. NET existing paging control? This goes back to when I changed my DW asp paging, that I didn't know much about the program, just tinkering, not even talking about performance issues. I was upset, and then called my personal technical director Zhang to help me see, At that time Zhang always looked at me with a dismissive look, and said something: Is it worth it?
Then to my hand-crafted ASP paging, and can't go on, Zhang always throw me a bunch. NET code: Do your own research. And then lost a word: do it with. NET, a few words to fix, do not bother.
Later I found that the previous paging is all the entire data set read and then do the paging process, once the data volume is too large, processing will be very slow, or even the server crashes. Then the previous page cannot scroll like a cursor, always fixed in a group, it is impossible to achieve the current page number in the middle of the effect.
And then I'll say. NET pagination control, indeed a few words can be done, but the flaw is I found the first problem, belongs to the data all read out and then processing of the kind, no efficiency, so finally started, pure handmade to create ASP.
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--Create Date:2007-01-30-Description: High-performance paging-============================================= 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_nam e) 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 Set @Cursor = @Count-@MaxPageSize + 1-- Otherwise, the remaining record of the last page is returned else set @Cursor = @Count-(@Count% @MaxPageSize) + 1 END--pointer to the page start set Ro Wcount @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 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[i])); } tagbox.innerhtml = tag.gethtml;
The method of handling page numbers to the session is not provided, there is no mark. Calling the stored procedure to return parameters and records is similar to the batch data operation method I wrote earlier, just to define an output mode.
At the moment I think the code will be flawed, and so on when the project later code review of the time to strengthen it, I would like to say is not to be dragged down by the things to be confused, so that they never improve, to hold the knowledge of their own attitude to do one thing, to their help will be obvious.