日期:2011-10-30  浏览次数:21037 次

函数如下:
<%
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
%>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" height="58">
<%
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
%>
<table border = 1 align = center>

<tr>
<%
Dim n
n = 0
do while n <= UBound(args)%>
<th>
<%response.write args(n)%>
</th>
<%
n = n + 1
loop
%>
</tr>
<%
do while NOT rs.EOF and i<intpagesize%>
<tr>
<%
Dim l
l = 0
do while l <= UBound(args)
%>
<td>
<%=rs(args(l))%>
</td>
<%
l = l + 1
loop
%>
</tr>
<%
i = i + 1
rs.MoveNext
loop
%>
</table>
<%
end if%>
</td>
</tr>
</table>
<div align="center"><br>
<%=intcur%> /<%=inttotal%>
<% if intcur>1 then %>
<a href="index.asp?page=previous&curpage=<%=intcur%>">上一页</a>
<%else%>
上一页
<%end if
intcur=cint(intcur)
inttotal=cint(inttotal)%>
<%if intcur<inttotal then%>
<a href="index.asp?page=next&curpage=<%=intcur%>">下一页</a>
<%else%>
下一页
<%end if%>
</div>
<%
rs.close
set rs = nothing
end function
%>





测试页面如下:
<!--#include file = "fenye.inc"-->
<%
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: 要求显示的数据库中的字段