asp如何显示数据分页的程序

    文章来源:万象互联 更新时间:2012-3-23 20:22:17
分享:

asp显示数据分页程序,以下是asp显示数据分页的程序分享给大家:

<!--#include file="conn.asp"-->
<%
const MaxPerPage=2
' 定义每页文章显示数
if not isempty(request("page")) then
 currentPage=cint(request("page"))
else
 currentPage=1
end if

' 取当前页数,如果是空就是第一页
sql="select questionid,questiontitle from t_question"
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
 '<a href="/a/db/" target="_blank"><u>数据库</u></a>中文章数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,"aaaa.asp"
  showContent
  showpage totalput,MaxPerPage,"aaaa.asp"
 else
  if (currentPage-1)*MaxPerPage<totalPut then
   rs.move (currentPage-1)*MaxPerPage
   dim bookmark
   bookmark=rs.bookmark
   showpage totalput,MaxPerPage,"aaaa.asp"
   showContent
   showpage totalput,MaxPerPage,"aaaa.asp"
  else
   currentPage=1
   showpage totalput,MaxPerPage,"aaaa.asp"
   showContent
   showpage totalput,MaxPerPage,"aaaa.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
%>
<div align=center><%=rs("questiontitle")%></div>
<% ' 选择显示<a href="/a/db/" target="_blank"><u>数据库</u></a>内容
 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 if
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
%>

 

版权说明:本站原创文章,由万象互联SEO优化发表.
本文地址:https://www.hulian.top/zixun/post/4764.html
在线咨询
  • 在线时间
  • 8:00-21:00