• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

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

发布: 2007-6-30 18:56 | 作者: admin | 来源: | 查看: 12次 | 进入软件测试论坛讨论

领测软件测试网 <%
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
%>

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网