新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > Web开发 > Asp教程 > 正文:近日很多朋友咨询分页的问题,我就传个我自己写的完整的分页程序吧,希望对大家有帮助

近日很多朋友咨询分页的问题,我就传个我自己写的完整的分页程序吧,希望对大家有帮助

新客网 XKER.COM 2003-07-11 来源: 收藏本文
<%
set rs=createobject("adodb.recordset")
rs.open "select * from table",conn,1,1
if rs.eof then
    response.write "No records!"
else
    if not isempty(request("page")) then
        currentPage=cint(request("page"))
    else
        currentPage=1
    end if

    rs.pagesize=10
    totalPut=rs.recordcount  
    totalPage=rs.pagecount
    MaxPerPage=rs.pagesize
    if currentpage<1 then
        currentpage=1
    end if
    if currentpage>totalPage then
        currentpage=totalPage
    end if
    if currentPage=1 then
        showhead  '分页结果显示头,如共有几条几页记录之类的东东
        showContent  '显示该页记录集
        showfoot  '分布结果显示尾,如至其它页面间的链接等
    else
        if (currentPage-1)*MaxPerPage<totalPut then
            rs.move  (currentPage-1)*MaxPerPage
            showhead
            showContent
            showfoot
        else
        end if
    end if
end if

sub showContent
dim i,j
i=1
do while not (rs.eof or err)
%>
     '在此输入单记录显示模式
        <%
    if i>=MaxPerPage then exit do  
    i=i+1
    rs.movenext
loop
end sub  

至其它页面的链接代码:
1、链接到上页、下页、首页和尾页
<%
If currentPage <> 1 Then
    Response.Write "<A HREF=show.asp>[第一页]</A> "
    Response.Write "<A HREF=show.asp?Page=" & (currentPage-1) & ">[上一页]</A> "
End If
If currentPage <> rs.PageCount Then
    Response.Write "<A HREF=show.asp?Page=" & (currentPage+1) & ">[下一页]</A> "
    Response.Write "<A HREF=show.asp?Page=" & totalPage & ">[最后一页]</A> "
End If
%>
2、跳转至其中的任一页面
<form action="show.asp" method="GET" align="right" style="margin-top: 0px; margin-bottom: 0px">
<%for i=1 to n
    response.write "<option value="& i  
    if currentpage=i then  
        response.write " selected"
    end if
    response.write ">"& i &"</option>"
next
response.write "</select>"
response.write "<input class=buttonface type='submit'  value='GO'  style='font-family: 宋体; font-size: 8pt;height:19'>"
%>
3、链接到当前页开始的后十页
<%
for j=currentpage+1 to currentpage+10
    if j>totalpage then exit do%>
    <a href="show.asp?page=<%=j%>"><%=j%></a> 
    <%
next
%>
收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐