ASP万用分页程序

所属分类: 网络编程 / ASP编程 阅读数: 860
收藏 0 赞 0 分享

下面这段是基本的分页代码: 

<% 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 %>

  系统已经为数据分页了,下面就看看这次探讨的关键问题分页函数的定义

<% 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 %>

  把上面这个分页函数代码COPY存成一个ASP文件,在需要使用的页面里用include来引入他调用的时候只要 Call("/你调用的文件名?")就ok了,比如我的 news页面里要调用那么就是<%Call("/news.asp?")%>

刚才我们所到这是有限制的意思就是说第一段代码里除了sql查询内容和输出内容可以更改,其他的声明记录集的对象,page, pages, allpages这些变量都不能更改,否则将无法运行~其实这个程序是无关紧要的,最主要的就是,这个分页函数可以在任何一个asp叶面里调用。

更多精彩内容其他人还在看

asp中去除内容HTML标签的三个function函数

asp中去除内容HTML标签的三个function函数
收藏 0 赞 0 分享

chr(9)、chr(10)、chr(13)、chr(32)、chr(34)讲解

chr(9)、chr(10)、chr(13)、chr(32)、chr(34)讲解
收藏 0 赞 0 分享

方便的大家admin及admin888 经过 md5加密后16位和32位代码

方便的大家admin及admin888 经过 md5加密后16位和32位代码
收藏 0 赞 0 分享

可用的ASP无重复数字随机函数, 数组实现, 并应用于随机显示记录集

可用的ASP无重复数字随机函数, 数组实现, 并应用于随机显示记录集
收藏 0 赞 0 分享

asp动态级联菜单代码

asp动态级联菜单代码
收藏 0 赞 0 分享

ASP中经常使用的SQL语句与教程说明

ASP中经常使用的SQL语句与教程说明
收藏 0 赞 0 分享

实例分析之用ASP编程实现网络内容快速查找的代码

实例分析之用ASP编程实现网络内容快速查找的代码
收藏 0 赞 0 分享

服务端 VBScript 与 JScript 几个相同特性的写法与示例

服务端 VBScript 与 JScript 几个相同特性的写法与示例
收藏 0 赞 0 分享

ASP 环境下 VBS 事件应用 示例代码

ASP 环境下 VBS 事件应用 示例代码
收藏 0 赞 0 分享

asp 之上传漏洞终结篇

asp 之上传漏洞终结篇
收藏 0 赞 0 分享
查看更多