ASP universal paging Program

Source: Internet
Author: User
Tags servervariables

This is just an ASP little skill. Although it is suitable for calling this function in different file names, it is also a prerequisite. Let's take a closer look at the original principles.
The following section shows the basic page Code :

<% SQL = "select ........................ SQL statement omitted
Set rs = server. Createobject ("ADODB. recordset ")
Rs. Open SQL, Conn, 1, 1
If not Rs. EOF then
Pages = 30' defines the number of records displayed per page
Rs. pagesize = pages defines the number of records displayed on each page
Allpages = Rs. pagecount calculate the total number of pages that can be divided.
Page = request. querystring ("page ")'
'If statement is a basic troubleshooting method
If isempty (PAGE) or CINT (PAGE) <1 then
Page = 1
Elseif CINT (PAGE)> allpages then
Page = allpages
End if
Rs. absolutepage = page
Do while not Rs. EOF and pages> 0%>
Output the content you want ..................
<% Pages = pages-1
Rs. movenext
Loop
Else
Response. Write ("the database has no content! ")
End if
Rs. Close
Set rs = nothing %>

The system has already paged the data. Let's take a look at the definition of the paging function, which is a key issue discussed this time.

<% Sub pageurl (purl)
Dim eurl
Txts = request. servervariables ("url ")
Txts = left (txts, limit Rev (txts, "/", Len (txts)-1)
Eurl = "http: //"; & request. servervariables ("SERVER_NAME") & txts
For I = 1 to allpages
TXT = ""
TXT = "<strong>"
TXT = TXT & "<a href =" & eurl & purl & "page =" & I & ">"
If I = CINT (PAGE) Then TXT = TXT & "<font color = 'bb000000'>"
TXT = TXT & (I)
If I = CINT (PAGE) Then TXT = TXT & "</font>"
TXT = TXT & "</a> upload </strong>"
Response. Write (txt)
Next
End sub %>

Copy the code of the paging function above into an ASP file, and use include in the page to introduce the file name called by him as long as call ("/Your called file name? ") It's OK. For example, if you want to call the service on my news page, it is <% call ("/news. asp? ") %>

what we just mentioned is restricted. That is to say, in the first code, except for SQL query content and output content, other declared record set objects, pages, pages, all the variables in allpages cannot be changed; otherwise, they cannot be run ~ In fact, this Program is irrelevant. The most important thing is that this paging function can be called in any ASP leaf.

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.