完美的ASP分页脚本

[浏览190]
'PageinationRecordSet  如果返回false,说明 Adodb.RecrodSet集 为空
'RecordSet  Adodb.RecrodSet集
'PageId  当前所在页
'PageSize  每页显示多少条?
'*PageCount 返回页码总数
function PageinationRecordSet(byref RecordSet,byref PageId,byval PageSize,byref PageCount)
    if RecordSet.eof then
        PageinationRecordSet = false
    else
        RecordSet.PageSize = PageSize
        PageCount = RecordSet.PageCount
        if PageId > PageCount then PageId = PageCount
        RecordSet.absolutePage = PageId
        PageinationRecordSet = true
    end if
end function
 
'PageId  当前所在页
'PageCount  页码总数
'urlTemplate  链接模板
function PageinationPageList(byval PageId,byval PageCount,byval urlTemplate)
    dim codeTemp,iPage
     
    if PageCount > 0 then
        codeTemp ="<ul class=""pagination"">"
         
        if PageId <= 1 then codeTemp = codeTemp &"<li class=""disabled"">"else codeTemp = codeTemp &"<li>"
        codeTemp = codeTemp &"<a href="""& replace(urlTemplate,"{pg}",1) &"""> 首页 </a></li>"
        if PageId <= 1 then codeTemp = codeTemp &"<li class=""disabled"">"else codeTemp = codeTemp &"<li>"
        codeTemp = codeTemp &"<a href="""& replace(urlTemplate,"{pg}",PageId-1) &""">上一页</a></li>"
         
        for iPage = PageId - 5 to PageId + 5
            if iPage = PageId then
                codeTemp = codeTemp &"<li class=""active""><a href="""& replace(urlTemplate,"{pg}",iPage) &""">"& iPage &"</a></li>"
            elseif iPage < PageId and iPage > 0 then
                codeTemp = codeTemp &"<li><a href="""& replace(urlTemplate,"{pg}",iPage) &""">"& iPage &"</a></li>"
            elseif iPage > PageId and iPage <= PageCount then
                codeTemp = codeTemp &"<li><a href="""& replace(urlTemplate,"{pg}",iPage) &""">"& iPage &"</a></li>"
            end if
        next
         
        if PageId >= PageCount then codeTemp = codeTemp &"<li class=""disabled"">"else codeTemp = codeTemp &"<li>"
        codeTemp = codeTemp &"<a href="""& replace(urlTemplate,"{pg}",PageId + 1) &""">下一页</a></li>"
        if PageId >= PageCount then codeTemp = codeTemp &"<li class=""disabled"">"else codeTemp = codeTemp &"<li>"
        codeTemp = codeTemp &"<a href="""& replace(urlTemplate,"{pg}",PageCount) &""">尾页</a></li>"
         
        PageinationPageList = codeTemp &"</ul>"
    end if

end function

测试代码:


pgId = Request.QueryString("pageid")   '当前页码
pgSize = 10'每页大小
rsId = 0
Rs.Open Query,Conn,1,1
if PageinationRecordSet(Rs, pgId, pgSize, pgCount) then
    do while not Rs.Eof and rsId < pgSize
        rsId = rsId + 1
         
        '列表内容
         
        Rs.MoveNext
    loop
end if
Rs.Close
 
'共 pgCount 页
response.write PageinationPageList(pgId, pgCount,"./list.asp?pageid={pg}") '输出分页代码


关闭 ]
友情链接

Copyright © 2014 ASP技巧教程源码大全 All Rights Reserved
晋ICP备14006235号-3 页面执行时间:125.000毫秒 返回顶部