十分通用的asp数字分页函数(自定义变量名,数字分页个数,带Get参数)

<%
function FenYe(CurPage,PageCount,ShowNums,Pname,UrlParams)
'CurPage 当前页码
'PageCount 总页数
'ShowNums 设定数字导航显示的个数
'Pname 传递分页值的变量名称
'UrlParams 为连接参数 比如:&a=1&b=2

CurPage=Cint(CurPage)
PageCount=Cint(PageCount)
ShowNums=Cint(ShowNums)


if cint(CurPage)>=ShowNums then
    if ShowNums mod 2 = 0 then
        ks=CurPage-ShowNums/2+1
        js=CurPage+ShowNums/2
    else
        ks=CurPage-int(ShowNums/2)
        js=CurPage+int(ShowNums/2)
    end if
    if ks<1 then
        ks=1
        js=ks+(ShowNums-1)
    end if
    
    if js>cint(PageCount) then
        js=PageCount
        ks=js-(ShowNums-1)
    end if
else
    if cint(PageCount)>ShowNums then
        ks=1
        js=ShowNums
    else
        ks=1
        js=PageCount
    end if
end if

if CurPage>1  then
response.Write("<a href='?"&Pname&"=1"&UrlParams&"' title='首页'>&nbsp;&lt;&lt;&nbsp;</a>&nbsp;<a href='?"&Pname&"="& CurPage-1 & UrlParams&  "' title='上一页'>&nbsp;&lt;&nbsp;</a>&nbsp;")
else
response.Write("<span class=""disabled"">&nbsp;&lt;&lt;&nbsp;</span>&nbsp;<span class=""disabled"">&nbsp;&lt;&nbsp;</span>&nbsp;")
end if

for i= ks to js
if cint(i)=cint(CurPage) then
response.write "<span class=""disabled"">&nbsp;"&i&"&nbsp;</span> "
else
response.write "&nbsp;<a href=?"&Pname&"="&i&UrlParams &">&nbsp;"&i&"&nbsp;</a>&nbsp;"
end if
next

if cint(CurPage)<cint(PageCount) then
response.Write("<a href='?"&Pname&"="& CurPage+1 & UrlParams  & "' title='下一页'>&nbsp;&gt;&nbsp;</a>&nbsp;<a href='?"&Pname&"="& PageCount & UrlParams  & "' title='尾页'>&nbsp;&gt;&gt;&nbsp;</a>&nbsp;")
else
response.Write("<span class=""disabled"">&nbsp;&gt;&nbsp;</span>&nbsp;<span class=""disabled"">&nbsp;&gt;&gt;&nbsp;</span>&nbsp;")
end if

end function
%>


<%
'解决UrlParams带空格的问题
function FenYeUrlParamCheck(ConstVal,VarVal)
if len(VarVal)>0 then
    FenYeUrlParamCheck="&"&ConstVal&"="&escape(VarVal)
end if
end function
%>

 

posted @ 2012-05-02 01:57  moretop  阅读(892)  评论(0编辑  收藏  举报