分页函数 (转)

本文介绍了一个用于ASP页面的自定义分页函数,该函数能够简化分页操作并提高开发效率。通过传递记录集、每页记录数及所需显示的字段等参数,可以实现灵活的分页展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

分页函数 (转)[@more@]

函数如下:

private function fenye(rs, pagesize,args)
Dim intcur
Dim intpagesize
Dim total
Dim inttotal

args = split(args,",")
if  Request.querystring("page")="" then 
 intcur=1
 page = "first"
else
 select  case  request("page")
   case  "first"
   intcur=1
  case  "previous"
   intcur=cint(request("curpage"))
   intcur=intcur-1
  case  "next"
   intcur=cint(request("curpage"))
   intcur=intcur+1
  case  "last"
   intcur=cint(request("lastpage"))
  case  else 
  intcur=request("page")
 end  select
end  if
%>


  if rs.eof then
 response.write "没有栏目:("
 else
 intpagesize=pagesize
 rs.pagesize=intpagesize
 if not rs.eof then
 rs.AbsolutePage=intcur
 end if
 total=rs.recordcount
 inttotal=rs.pagecount
 Dim i
 i = 0
 %>
 

 
 
oop
 %>
 

 
 

  end if%>
 
 



  / 
 1  then  %>
  ASP?page=previous&curpage=">上一页
 
 上一页
  intcur=cint(intcur)
 inttotal=cint(inttotal)%>
 
  下一页
 
 下一页
 

rs.close
set rs = nothing
end function
%>

 

 

测试页面如下:

<!--#include file = "fenye.inc"--&gt
dim conn 
dim connstr
dim rst
on error resume next
connstr="dbQ="+server.mappath("Nwind.mdb")+";DefaultDir=;driver={microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
set rst = server.createobject("adodb.recordset")
rst.open "select * from orders",conn,1,1
call fenye(rst,7,"OrderID,CustomerID,ShipVia")
rst.close
set rst = nothing
conn.close
set conn = nothing
%>

说明:

使用时在asp页面顶部加入
<!--#include file = "fenye.inc">

在需要分页的地方调用函数:
如:call fenye(rst,7,"OrderID,CustomerID,ShipVia")

函数原型:
variant fenye(recordset rs,integer pagesize,String args)

参数说明如下:
rs:  传入的recordset
n:  要求每页显示的记录数
columns:  要求显示的数据库中的字段


  做这样一个分页函数是因为有时自己写分页的时候觉得不是那么方便,每个地方都写一遍很浪费,也看到很多朋友都在问这个问题,所以写这样一个函数大家参考一下吧,第一次写这种东西,感觉很低级,但是还是希望大家捧场。。。。。谢谢!!!欢迎各种意见和建议!顺便说一下,这种ado的分页方法,我觉得实在是效率很低,因为我每次只要7条记录但是却要取出一个上百条甚至上千条的纪录集,如果一个服务器端的数据量少也就罢了,如果。。。。唉。。。所以,以后会再做几个不同原理的分页函数!


  我的eMail:
   xuchi@uibeonline.com


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-992352/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10752043/viewspace-992352/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值