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 paging 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? ") %>
This is restricted. That is to say, in the first code, except for the SQL query content and output content, other declared record set objects, page, 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. Pages are not beautiful yet. Experts can modify and modify pages. If you can send them to me, I will post them to you!

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.