ASP million paging program

Source: Internet
Author: User
Tags servervariables

This is just an ASP tip class thing, although it is suitable for each of the different file names call this function, but there are prerequisites, let's take a closer look at the story.

The following section is the basic page-splitting code:

<% sql = "select……………………省略了sql语句
 Set rs=Server.Createobject("ADODB.RECORDSET")
 rs.Open sql, conn, 1, 1
 if not rs.eof then
  pages = 30 ’定义每页显示的记录数
  rs.pageSize = pages ’定义每页显示的记录数
  allPages = rs.pageCount’计算一共能分多少页
  page = Request.QueryString("page")’通过浏览器传递的页数
  ’if语句属于基本的排错处理
  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 %>
   这里输出你要的内容………………
   <% pages = pages - 1
   rs.MoveNext
  Loop
 else
  Response.Write("数据库暂无内容!")
 End if
 rs.Close
 Set rs = Nothing %>

The system has been paging the data, and here's a look at the key issues of this discussion the definition of paging function

<% SUB pageUrl(pUrl)
 Dim eUrl
 txts = Request.ServerVariables("URL")
 txts = left(txts,instrrev(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=’bb0000’>"
   txt = txt & (i)
   if i = Cint(Page) then txt = txt & "</font>"
    txt = txt & "</a> ∥ </strong>"
    Response.Write(txt)
 Next
END sub %>

Save the page function code copy as an ASP file, and use include in the page you want to use to bring in the call ("/the filename you called?"). OK, like the one on my news page is called <%call ("/news.asp?") %>

There's a limit to what we've been up to. That is, in the first code, in addition to the SQL query content and output can be changed, the other declared Recordset object, page, pages, allpages these variables can not be changed, otherwise it will not run ~ In fact, this program is irrelevant, the most important is , the paging function can be invoked in any ASP leaf. Pagination do not beautiful, experts can modify the changes, can be sent to me, I will be responsible for you to publish it!

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.