ASP easy-to-use paging class 1.2.00

Source: Internet
Author: User

This ASP generic paging class is easy to use, and the speed depends on the actual application: if the total number of records (intrecordcount attribute) has been specified, it can support millions of data applications; if a Statistical Statement (strsqlcount attribute) is specified, it depends on the statistical efficiency of the statement. If neither of them is specified, the recordcount attribute value is obtained based on the query statement given by the user, of course, this efficiency will not be high. if you encounter problems in the application, use MSN to contact me: xiaoyuehen (AT) msn.com

Applicability:

1. For general paging requirements, you only need to specify the query statement and several other main parameters for ease of use.
2. The speed of paging depends on the efficiency of SQL statement execution.
3. You can specify the number of records statistical statement, or set the total number of record sets for customization.
4. If you do not like the paging navigation generated by the class, you can also set the redirection.

Example:

Custompageview. asp (the name is optional)

<% @ Language = "VBScript" codePage = "936" %> <% option explicit %> <! -- # Include file = "cls_pageview.asp" --> <% response. buffer = truedim intdatestartintdatestart = timer () rem ## open a database connection REM ################################# ################################ function F _ openconn () dim strdbpathdim connstrstrdbpath = ".. /DB/test. mdb "connstr =" provider = Microsoft. jet. oledb.4.0; Data Source = "connstr = connstr & server. mappath (strdbpath) set conn = server. createobject ("ADODB. conne Ction ") Conn. open connstrend functionrem ##################################### ########################### REM ## disable database connection REM ##### ######################################## ################### function F _ closeconn () if isobject (conn) thenconn. closeend ifset conn = nothingend functionrem ################################## ############################# REM obtaining execution time #### ################################## ########################## Function gettimeover (iflag) dim ttimeoverif iflag = 1 thenttimeover = formatnumber (timer ()-intdatestart, 6, true) gettimeover = "execution time:" & ttimeover & "seconds" elsettimeover = formatnumber (timer () -intdatestart) * 1000, 3, true) gettimeover = "execution time: "& ttimeover &" millisecond "End ifend functionrem ############################## ################################### dim strlocalurlst Rlocalurl = request. servervariables ("script_name") dim intpagenowintpagenow = request. querystring ("page") dim intpagesize, strpageinfointpagesize = 10dim arrrecordinfo, idim Conn, SQL, sqlcountsql = "select [product ID], [product name], [unit] "& _" from [product 0202] "& _" order by [product ID] ASC "sqlcount =" select count ([product ID]) "& _" from [product 0202] "F _ openconndim clsrecordinfoset clsrecordinfo = new cls_pageviewrem record set value Priority: strsqlcount> intrecordcountrem: When strsqlcount has a value, intrecordcount does not work. Therefore, to manually set the total number of records, set intrecordcount, leave strsqlcount blank REM. If neither of the preceding settings is set, take the recordcount attribute after execution of strsql. clsrecordinfo. intrecordcount = 2816clsrecordinfo. strsqlcount = sqlcountrem because strsqlcount is set here, the total number of records is calculated using this statement. rem sets the SQL query statement clsrecordinfo. strsql = sqlrem set the number of clsrecordinfo displayed per page. intpagesize = intpagesizerem set the current display page clsrecordin Fo. intpagenow = intpagenowrem set to switch to page clsrecordinfo. strpageurl = strlocalurlrem sets the page direction parameter clsrecordinfo. strpagevar = "page" clsrecordinfo. objconn = connarrrecordinfo = clsrecordinfo. arrrecordinfostrpageinfo = clsrecordinfo. strpageinfoset clsrecordinfo = nothingf _ closeconn %> <HTML> 

Class file:

Cls_pageview.asp

<% REM ************************************* * ************ Author: xiaoyuehen REM ** ASP General paging class REM ** version: 1.2.00rem ** last modified: 2005-4-18rem ** copyright Description: Any copy can be performed on the premise that the document is complete, propagation. rem ** contact Author: xiaoyuehen (AT) MSN. comrem *************************************** * ******* class cls_pageviewprivate sbooinitstateprivate sstrpageurlprivate sstrpagevarprivate sstrsqlprivate sstrsqlcountprivate sintrecordcountprivate sintp Agesizeprivate sintpagenowprivate sintpagemaxprivate sobjconnprivate extends sub class_initializecall clearvars () end subprivate sub class_terminate () set sobjconn = nothingend subpublic sub clearvars () sbooinitstate = nation = "" sstrpagevar = "page" sintrecordcount = 0 sintpagesize = 20 sintpagenow = 0 region = 0end subprivate sub clearmainvars () sstrsql = "" End subrem # SQL statement Public property let strsql (value) sstrsql = valueend propertyrem # SQL statement public property let strsqlcount (value) sstrsqlcount = valueend propertyrem # redirection address public property let strpageurl (value) sstrpageurl = valueend propertyrem # number of records displayed on each page public property let intpagesize (value) sintpagesize = tonum (value, 20) end propertyrem # database connection object public property let objconn (value) set sobjconn = valueend propertyre M # current page public property let intpagenow (value) sintpagenow = tonum (value, 1) end propertyrem # Set the total number of records public property let intrecordcount (value) sintrecordcount = tonum (value, -1) If sintrecordcount <0 then sintrecordcount =-1end propertyrem # page parameter public property let strpagevar (value) sstrpagevar = valueend propertyrem # obtain the current page public property get intpagenow () intpagenow = singpagenowend propertyrem ## Public property get strpageinfo () strpageinfo = sstrpageinfoend propertyrem # retrieve record set, two-dimensional array or string. You must use isarray () to judge public property get arrrecordinfo () during cyclic output () call initclass () if not sbooinitstate thenresponse. write ("Paging class initialization failed, please check the various parameters") Exit propertyend ifdim RS, sqlsql = sstrsqlset rs = server. createobject ("ADODB. recordset ") if the record count statistics statement is not empty, use the first field value after the statement is executed as the record count if sstrsqlcount <>" "thenrs. open sstrsql Count, sobjconn, 1, 1if not (RS. EOF or Rs. bof) thensintrecordcount = RS (0) elsesintrecordcount = 0end IFRS. closeend IFRS. open SQL, sobjconn, 1, 1rem if no record statistics statement is set and the total number of records is not set, the recordcount attribute of the record set is obtained. if sintrecordcount <0 thensintrecordcount = Rs. recordcountend ifif sintrecordcount <0 then sintrecordcount = 0 'generate the page information call initpageinfo () if not (RS. EOF or Rs. bof) thenrs. pagesize = sintpagesizers. absolutepage = sin Tpagenowif not (RS. EOF or Rs. bof) thenarrrecordinfo = Rs. getrows (sintpagesize) elsearrrecordinfo = "" End ifelsearrrecordinfo = "" End IFRS. closeset rs = nothingcall clearmainvars () end propertyrem # initialize the page information private sub initpageinfo () sstrpageinfo = "" dim surlsurl = sstrpageurlif instr (1, Surl ,"? ", 1)> 0 thensurl = Surl &" & "& sstrpagevar &" = "elsesurl = Surl &"? "& Define &" = "End ifif exist <= 0 then sintpagenow = 1if sintrecordcount mod sintpagesize = 0 then = sintrecordcount/sintpagesize + 1end ifif exist> then healthy sintpagemaxif sintpagenow <= 1 homepage = "homepage previous" elsesstrpageinfo = sstrpageinfo & "<a href =" & Surl & "1"> homepage </a> "sstrpageinfo = sstrpageinfo & "<a href =" "& Surl & (sintpagenow-1) & "> previous page </a>" End ifif sintpagemax-sintpagenow <1 items = sstrpageinfo & "last page of the next page" elsesstrpageinfo = sstrpageinfo & "<a href =" & Surl & (sintpagenow + 1) & "> next page </a>" sstrpageinfo = sstrpageinfo & "<a href =" "& Surl & sintpagemax &" "> last page </a>" End ifsstrpageinfo = sstrpageinfo & "Page: <strong> <font color = "" #990000 ""> "& sintpagenow &" </font>/"& sintpagemax &" </strong> "sstrpageinfo = sstrpageinfo &" <strong> "& sintrecordcount &" </strong> records <strong> "& sintpagesize &" </strong> entries/pages "End subrem # convert long integers to private function tonum (s, default) S = S & "" If S <> "" And isnumeric (s) thentonum = clng (s) elsetonum = defaultend ifend functionrem # class initialization public sub initclass () sbooinitstate = trueif not (isobject (sobjconn) thensbooinitstate = falseresponse. write ("database connection not specified") response. end () end ifif trim (sstrsql) = "" thensbooinitstate = falseresponse. write ("SQL statement not specified") response. end () end ifsintpagesize = tonum (sintpagesize, 20) if (sintpagesize <1) or (sintpagesize> 100) thensbooinitstate = falseresponse. write ("the number of records per page is not set or does not comply with the rules (1-100)") response. end () end ifsintpagenow = tonum (sintpagenow, 1) sintrecordcount =-1end subend Class %>

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.