这个分页代码使用很简单,只有4个步骤:
(1)构造 SQL 查询语句、设置数据库连接字符串、设置每页记录显示数目
(2)插入分页控制代码 navigator_init.inc 文件
(3)在页面的适当地方(即你想显示“上页、下页”的地方),插入分页导航代码 navigator.inc
(4)用循环显示本页记录
需要分页的 ASP 文件
sample.ASP
test
分页控制代码:
navigator_init.inc
0 then
rs.PageSize = thePageSize
rs.AbsolutePage = 1
theCurrentPageNum = 1
Set Session(theCurrentRS) = rs
end if
else
Set rs = Session(theCurrentRS)
if rs.recordcount > 0 then
rs.AbsolutePage = theCurrentPageNum
end if
End If
'构造导航条
href_first = theScript & "?mo=0&pn=1"
href_prev = theScript & "?mo=0&pn=" & (theCurrentPageNum-1)
href_next = theScript & "?mo=0&pn=" & (theCurrentPageNum+1)
href_last = theScript & "?mo=0&pn=" & rs.pagecount
strnav_first= "首页"
strnav_prev = "前页"
strnav_next = "后页"
strnav_last = "末页"
if rs.pagecount > 1 then
'在首页
if theCurrentPageNum = 1 then
strnav_first= "首页"
strnav_prev = "前页"
end if
'在末页
if theCurrentPageNum = rs.pagecount then
strnav_next = "后页"
strnav_last = "末页"
end if
else
strnav_first= "首页"
strnav_prev = "前页"
strnav_next = "后页"
strnav_last = "末页"
end if
strnav = strnav_first & " " & strnav_prev & " " & strnav_next & " " & strnav_last
' 由于在 listrecords 函数中,当显示完所有记录时将关闭 rs ,因此先把 rs.recordcount 保存起来
theRsCount = rs.recordcount
%>
分页导航代码:
navigator.inc

