[心缘地方]同学录
首页 | 功能说明 | 站长通知 | 最近更新 | 编码查看转换 | 代码下载 | 常见问题及讨论 | 《深入解析ASP核心技术》 | 王小鸭自动发工资条VBA版
登录系统:用户名: 密码: 如果要讨论问题,请先注册。

[文章整理][ASP]我改写的分页代码,有前十页,后十页的。

上一篇:[文章整理][JSP]javaBean的class文件存放位置说明
下一篇:[文章整理][ASP]我鼓捣的数据库数据生成word文档的方法!

添加日期:2006/2/15 11:50:11 快速返回   返回列表 阅读4306次
显示当前十页,前十页,后十页,首页,前页,后页,尾页。
支持附加的条件,如查询的条件也可以附加进来,总之可以分页了。
=========================================如:
前十页  11 12 13 14 15 16 17 18 19 20 后十页 首页 前页 后页  尾页
=============================================
用两个子过程咔嚓起来了,调用方法很简单,举例如下:


<!--#include file="/inclue/listpages.asp"-->
......
<%
     myPagesize=10
......
     rs.open sql,conn,1,1
     myPages(rs,myPagesize)   '----紧接着调用这个
.......
    mycondition="&keyword="&keyword    '-----如还有关键字这个附加条件,注意开始有个&。
.......
%>


在需要显示分页的地方。用listpages(mycondition)就行了。
显示纪录的时候,就

line=myPagesize
do while not rs.eof and line>0
   .....
   rs.movenext
   line=line-1
loop


ok了。注意可能变量没有定义全哦,我比较懒,很少定义变量。 :D
================================================
代码如下:


<%sub listpages(mycondition)
    if pages<1 then
        exit sub
    end if
    response.write " 页码:"
    if p>0 then
        response.write    "<a href="&request.ServerVariables("script_name")&"?currentpage=10&p="&p-1&mycondition&">[上十页]</a> "
    end if
    '-------------------下面写出当前十个页码
    for i=1 to 10
        if (p*10+i)>pages then exit for
        if currentpage=i then
            response.write "<a style='color:blue' "
        else
            response.write "<a "
        end if 
        response.write "href="&request.ServerVariables("script_name")&"?currentpage="&i&"&p="&p&mycondition&">["&(p*10+i)&"]</a> "    
     next
     '--------------------察看下十页的连接
    if (p*10+10)<pages then
        response.write "<a href="&request.ServerVariables("script_name")&"?currentpage=1&p="&p+1&mycondition&">[下十页]</a>" 
    end if
    '-----------------------------------------------上下页导航
    response.write "   "
    if p>0 and currentpage=1 then
        response.write  "<a href="&request.ServerVariables("script_name")&"?currentpage=10&p="&p-1&mycondition&">[上页]</a> "
    elseif currentpage>1 then
        response.write  "<a href="&request.ServerVariables("script_name")&"?currentpage="¤tpage-1&"&p="&p&mycondition&">[上页]</a> "
    end if
    '===上页
    if (p*10+currentpage)<pages and currentpage=10 then
        response.write  "<a href="&request.ServerVariables("script_name")&"?currentpage=1&p="&p+1&mycondition&">[下页]</a> "
    elseif (p*10+currentpage)<pages then
        response.write  "<a href="&request.ServerVariables("script_name")&"?currentpage="¤tpage+1&"&p="&p&mycondition&">[下页]</a> "
    end if
    '===下页
      if (p*10+currentpage)>1 then
        response.write "<a href="&request.ServerVariables("script_name")&"?currentpage=1&&p=0"&mycondition&">[首页]</a> " 
      end if
    '===首页
      if (p*10+currentpage)<pages then
        response.write "<a href="&request.ServerVariables("script_name")&"?currentpage="&((pages-1) mod 10)+1&"&p="&((pages-1)\10)&mycondition&">[尾页]</a> "
      end if
      '===尾页
      response.write "第<b>"&(p*10+currentpage)&"/"&Pages&"</b>页 共<b>"&Records&"</b>条记录"
end sub

sub myPages(myRS,mysize)  '------mysize为内部变量(主页面没有定义),myRS为主页面传递过来的RS对象(地址传递)
    if myRS.eof and myRS.bof then str="没有纪录"
    if str="" then
        if mysize="" or NOT IsNumeric(mysize) then
            mysize=15
        end if
        myRS.PageSize=mysize
        pages=myRS.pagecount
        records=myRS.recordcount
        On Error Resume Next '取得数字
        currentPage=request("currentPage")
        if currentPage="" then
            currentPage=1
        end if
        currentPage=CInt(currentPage)
        if Err.Number <> 0 Then
            currentPage=1
            Err.Clear
        end if
        if currentPage<1 then
            currentPage=1
        elseIf currentPage>10 then
            currentPage=10
        end if
        '----------------处理p
        p=request("p")
        if p="" then
            p=0
        end if
        p=CLng(p)
        if Err.Number <> 0 Then
            p=0
            Err.Clear
        end if
        if p<0 then
            p=0
        end if
        '--判断是否出了页数范围
        nowPage=p*10+currentPage
        if nowPage>pages then
            p=(pages-1)\10
            currentPage=((pages-1) mod 10)+1
        end if
        myRS.absolutepage=p*10+currentPage
    else
       currentPage=1
       records=0
       pages=1
    end if
end sub

dim pages,records,currentPage,p '--------定义变量,这些变量在主页面中,进行地址传递%>


===========================================
 

评论 COMMENTS
没有评论 No Comments.

添加评论 Add new comment.
昵称 Name:
评论内容 Comment:
验证码(不区分大小写)
Validation Code:
(not case sensitive)
看不清?点这里换一张!(Change it here!)
 
评论由管理员查看后才能显示。the comment will be showed after it is checked by admin.
CopyRight © 心缘地方 2005-2999. All Rights Reserved