ASP 分页函数

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>分页示例</title>
</head>
<%
    ' Pagination Function
    ' Created by Bendy on 2010-12-11
    SUB Pager(intTotalRecord, intPageSize, intCurrentPage, strUrl)
       
        if (not IsNumeric(intTotalRecord) or not IsNumeric(intPageSize) or not IsNumeric(intCurrentPage)) then
            exit sub
        end if
       
        intTotalRecord = Clng(intTotalRecord)
        intPageSize = Clng(intPageSize)
        intCurrentPage = Clng(intCurrentPage)
       
        ' Init variable
        dim intPageCount, intShowPageCount, intBeginPage, intEndPage
        intShowPageCount = 10
       
        intPageCount = intTotalRecord \ intPageSize
        if (intTotalRecord mod intPageSize > 0) then
            intPageCount = intPageCount + 1   
        end if
        if (intPageCount <= 1) then
            exit sub
        end if
       
        if (intCurrentPage > intPageCount) then
            intCurrentPage = intPageCount
        end if
        if (intCurrentPage < 0) then
            intCurrentPage = 1
        end if

        if (intPageCount < intShowPageCount) then
            intShowPageCount = intPageCount
        end if
       
        intBeginPage = intCurrentPage -  intShowPageCount \ 2 + 1 ' ((intCurrentPage \ intShowPageCount) * intShowPageCount + 1)
        intEndPage = intCurrentPage +  intShowPageCount \ 2 '((intCurrentPage \ intShowPageCount + 1) * intShowPageCount)
       
        if (intBeginPage < 1) then
            intBeginPage = 1
            intEndPage = intShowPageCount
        end if
        if (intEndPage > intPageCount) then
            intBeginPage = intPageCount - intShowPageCount + 1
            intEndPage = intPageCount
        end if
       
        ' Get current URL
        if (strUrl = "") then
            strUrl = request.ServerVariables("SCRIPT_NAME")
            for each strQueryKey in request.QueryString
                if (strQueryKey <> "page") then
                    if (InStr(strUrl, "?") <= 0) then
                        strUrl = strUrl & "?" & strQueryKey & "=" & request.QueryString(strQueryKey)
                    else
                        strUrl = strUrl & "&" & strQueryKey & "=" & request.QueryString(strQueryKey)
                    end if
                end if
            next
        else
            if (InStr(strUrl, "?") <= 0) then
                strUrl = strUrl & "?1=1"
            end if
        end if
       
        ' Begin render the control
        response.Write("<table class='tblPager'><tr>")
        if (intBeginPage > 1) then
            response.Write("<td><a href='" & strUrl & "&page=1'>|<</a></td>")
        else
            response.Write("<td class='disable'>|<</td>")
        end if
        if (intCurrentPage > 1) then
            response.Write("<td><a href='" & strUrl & "&page=" & CStr(intCurrentPage-1) & "'><<</a></td>")
        else
            response.Write("<td class='disable'><<</td>")
        end if
        for i = intBeginPage to intEndPage
            if (i = intCurrentPage) then
                response.Write("<td class='currentPage'>" & CStr(i) & "</td>")
            else
                response.Write("<td><a href='" & strUrl & "&page=" & CStr(i) & "'>" & CStr(i) & "</a></td>")
            end if
        next
        if (intCurrentPage < intPageCount) then
            response.Write("<td><a href='" & strUrl & "&page=" & CStr(intCurrentPage+1) & "'>>></a></td>")
        else
            response.Write("<td class='disable'>>></td>")
        end if
        if (intEndPage < intPageCount) then
            response.Write("<td><a href='" & strUrl & "&page=" & intPageCount & "'>>|</a></td>")
        else
            response.Write("<td class='disable'>>|</td>")
        end if
        response.Write("</tr></table>")
    END SUB
%>
<style type="text/css">
    .tblPager {}
    .tblPager td { width:50px; border:solid 1px #efefef; text-align:center;}
    .tblPager .disable { color:#999999;}
    .tblPager .currentPage { font-weight:bold;}
</style>
<body>
<%    dim currentPage
    currentPage = request.QueryString("page")
    %>
<% call Pager(320, 10, currentPage, "pager.asp?b=3&c=3") %>
<br />
<% call Pager(0, 10, currentPage, "") %>
<br />
<% call Pager(8, 10, currentPage, "") %>
<br />
<% call Pager(320, 10, currentPage, "") %>
<br />
</body>
</html>

posted @ 2011-01-06 13:28  bndy  阅读(355)  评论(0编辑  收藏  举报