asp如何做一个分页程序?

时间:2010-07-11 21:13:00 

如何做一个分页程序?

    这在ASP中确实容易实现,但需要技巧,看看下面的分页代码和说明:

<anguage="vbscript" 
dim conn 
dim connstr 
dim totalPut 
dim CurrentPage 
dim TotalPages 
dim i,j 
dim sql 
dim rs 
on error resume next 
connstr="DBQ="+server.mappath("book.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};" 
set conn=server.createobject("ADODB.CONNECTION") 
conn.open connstr 
set rs=server.createobject("adodb.recordset") 
' 打开数据库 
const MaxPerPage=18 
' 定义每页文章显示数 
if not isempty(request("page")) then 
currentPage=cint(request("page")) 
else 
currentPage=1 
end if 
sql="select * from learning order by articleid desc" 
Set rs= Server.CreateObject("ADODB.Recordset") 
rs.open sql,conn,1,1 
if rs.eof and rs.bof then 
response.write "<p align='center'> 噢,还没有文章呢,正在添加中…</p>" 
else 
totalPut=rs.recordcount 
' 数据库中文章数totalput 
if currentpage<1 then 
currentpage=1 
end if 
' 统计总页数currentpage 
if (currentpage-1)*MaxPerPage>totalput then 
if (totalPut mod MaxPerPage)=0 then 
currentpage= totalPut \ MaxPerPage 
else 
currentpage= totalPut \ MaxPerPage + 1 
end if 
end if 
if currentPage=1 then 
showpage totalput,MaxPerPage,"index.asp" 
showContent 
showpage totalput,MaxPerPage,"index.asp" 
else 
if (currentPage-1)*MaxPerPage<totalPut then 
rs.move (currentPage-1)*MaxPerPage 
dim bookmark 
bookmark=rs.bookmark 
showpage totalput,MaxPerPage,"index.asp" 
showContent 
showpage totalput,MaxPerPage,"index.asp" 
else 
currentPage=1 
showpage totalput,MaxPerPage,"index.asp" 
showContent 
showpage totalput,MaxPerPage,"index.asp" 
end if 
end if 
rs.close 
end if 
set rs=nothing 
conn.close 
set conn=nothing 
sub showContent 
dim i 
i=0 
do while not rs.eof 

<a href="openarticle.asp?id=<=rs("articleid")>"><=rs("title")></a>[点击:<=rs("hits")>]<br> 
' 选择显示数据库内容 

i=i+1 
if i>=MaxPerPage then exit do 
' 当显示记录大于maxperpage时结束这页 
rs.movenext 
loop 
end sub 
function showpage(totalnumber,maxperpage,filename) 
' 求出当每页18篇文章时总共的页数 
dim n 
if totalnumber mod maxperpage=0 then 
n= totalnumber \ maxperpage 
else 
n= totalnumber \ maxperpage+1 
end if 
response.write "<form method=Post action="&filename&">" 
response.write "<p align='center'><font color='#000080'>>>分页</font> " 
if CurrentPage<2 then 
' 显示页数链接的条件 
response.write "<font color='#000080'>首页 上一页</font> " 
else 
response.write "<a href="&filename&"?page=1&>首页</a> " 
response.write "<a href="&filename&"?page="&CurrentPage-1&">上一页</a> " 
end if 
if n-currentpage<1 then 
response.write "<font color='#000080'>下一页 尾页</font>" 
else 
response.write "<a href="&filename&"?page="&(CurrentPage+1) 
response.write ">下一页</a> <a href="&filename&"?page="&n&">尾页</a>" 
end ifc 
response.write "<font color='#000080'>页次;</font><font color=red>"&CurrentPage&"</font><font color='#000080'>/"&n&"页</font>" 
response.write "<font color='#000080'>共<b>"&totalnumber&"</b>篇文章 <b>"&maxperpage&"</b>篇文章/页
</font>" 
response.write " <font color='#000080'>转到:</font><input type='text' name='page' size=4 maxlength=10 
class=smallInput value="Currentpage&">" 
response.write "<input class=buttonface type='submit' value='转到' name='cndok'></span></p></form>" 
end function 

标签:分页,程序,asp
0
投稿

猜你喜欢

  • SQL Server数据表压缩

    2024-01-25 21:47:12
  • setTimeout()与setInterval()方法区别介绍

    2024-04-22 13:24:09
  • Python对象的生命周期源码学习

    2022-04-04 23:21:24
  • 在Python的gevent框架下执行异步的Solr查询的教程

    2022-12-29 11:26:49
  • pyqt5 使用label控件实时显示时间的实例

    2021-01-29 14:54:17
  • Django连接MQTT的示例代码

    2022-10-04 22:40:39
  • Mysql存储过程和函数区别介绍

    2024-01-25 00:40:35
  • Python要求O(n)复杂度求无序列表中第K的大元素实例

    2023-07-30 13:18:01
  • PS笔刷,样式,形状、渐变、滤镜载入方式及使用

    2007-10-17 11:47:00
  • mysql查询一天,查询一周,查询一个月的数据

    2011-01-29 16:22:00
  • Python利用matplotlib.pyplot.boxplot()绘制箱型图实例代码

    2022-11-18 05:08:26
  • CMD命令操作MySql数据库的方法详解

    2024-01-16 08:31:57
  • python实现udp传输图片功能

    2022-09-24 16:35:01
  • 10个Python面试常问的问题(小结)

    2023-04-11 19:36:15
  • FlippingBook使用教程(附下载)

    2023-09-26 20:48:25
  • js求一组数中的最大数

    2008-04-10 12:00:00
  • 让你知道codepage的重要,关于多语言编码

    2008-01-31 12:04:00
  • python求最大公约数和最小公倍数的简单方法

    2022-08-31 22:05:45
  • 深入理解NumPy简明教程---数组3(组合)

    2023-07-15 06:22:39
  • D3.js实现拓扑图的示例代码

    2024-05-09 10:20:06
  • asp之家 网络编程 m.aspxhome.com