Asp. NET and MSSQL high performance paging instance code _mssql

Source: Internet
Author: User
Tags mssql rowcount

First is the stored procedure, which only extracts the data I need, and automatically returns the last page if the page exceeds the total number of data:

Set ANSI_NULLS on SET QUOTED_IDENTIFIER in Go--=============================================--author:clear--DESCRI Ption: High Performance Paging--http://www.cnblogs.com/roucheng/--============================================= Alter PROCEDURE [dbo ]. [Tag_page_name_select]--Incoming maximum number of records and current page number @MaxPageSize int, @PageNum int,--set an output parameter to return the total number of records for paging list use @Count int output as BEG
In the SET NOCOUNT on; DECLARE--Define the sort name parameter @Name nvarchar (50),--Define the cursor position @Cursor INT--First get the total number of records Select @Count = Count (tag_name) from [Viewdataba SE0716]. [dbo].
[View_tag]; --Define where the cursor needs to start 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 Begin--if the last 
The page is equal to the maximum number of records per record, returning the last full page if @Count% @MaxPageSize = 0 BEGIN if @Cursor > @MaxPageSize Set @Cursor = @Count-@MaxPageSize + 1 else Set @Cursor = 1 End--otherwise return the remaining record of the last page else set @Cursor = @Count-(@Count% @MaxPageSize) + 1 Ends--point the pointer to the page start Set Ro Wcount @Cursor-the location where the record begins is Select @Name = tag_name from [viewdatabase0716]. [dbo]. [View_tag] ORDER by TAg_name; --Sets the start position set ROWCOUNT @MaxPageSize-Gets the page record Select * from [viewdatabase0716]. [dbo].
[View_tag]  Where tag_name >= @Name ORDER by tag_name Set ROWCOUNT 0 End

The

is then the paging control (...). Generate HTML code method for ellipsis):

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; pr
Ivate 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>///gets the generated HTML///</summary> public string gethtml {getting {return insertstring.tostring ();}}/ 
<summary>///Gets the generated paging HTML///</summary> public string getpagehtml {getting {return pagestring.tostring ();} ///<summary>///Sets or gets the current number of pages///</summary> public int Pagenum {getting {return privatepagenum;} set {if (VA
Lue >= 1) {Privatepagenum = value; 
///<summary>///Sets or gets the maximum number of pages///</summary> public int MaxPageSize {getting {return privatemaxpagesize;}
set {if (value >= 1) {privatemaxpagesize = value;}}} <summary>///set or get maximum number of pages per display///</summary> public int Maxpages {getting {return privatemaxpages;} set {Pri
Vatemaxpages = value; }///<summary>///set or get total data///</summary> public int Datecount {getting {return privatecount;} set {Priva
Tecount = value; }///<summary>///get Data total pages///</summary> public int Allpage {getting {return privateallpage;}}///<sum
Mary>///Initialize paging///</summary> public void pagination () {pagestring = new StringBuilder ("");
Gets the total number of pages privateallpage = (int) math.ceiling ((decimal) Privatecount/(decimal) privatemaxpagesize); Prevent superscript or subscript out of bounds if (Privatepagenum > Privateallpage) {privatepagenum = Privateallpage;}//scrolling cursor paging int leftrange, Rightra
Nge, 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 = Privateallpage;
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) {...}}//If 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++) {//if (i = = privatepagenum) for the current page
{..}} or else {...}}
StringBuilder laststring = new StringBuilder (""); If on the last page if (Privatepagenum < Privateallpage) {...} else {...}//If in the last set of if (PrivaTepagenum + privatemaxpages) < Privateallpage) {...}} else {...}
Pagestring.append (laststring); ///<summary>///generate tag Category table///</summary> public void tagtable (Exdatarow myexdatarow) {insertstring.append
(...);  }

Call Method:

Get the paging setup and put the session
exrequest myexrequest = new Exrequest ();
Myexrequest.pagesession ("Tag_", new string[] {"page", "Size"});
Generate tag Paging
exstringbuilder tag = new Exstringbuilder ();
Set how many records to display each time
tag.maxpagesize = Convert.ToInt32 (session["tag_size"]);
Set the maximum number of page numbers 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 string[]{ 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)); 
   
    }

   

Related Article

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.