一个简单的asp分页代码转发
转发asp分页函数:
asp分页函数调用:
<div class="page_list"> <%=csPage1(strfilename,num,pagesiz,currentpage)%></div>
asp分页函数css样式:
.page_list{text-align:center;}.page_list a{display:inline-block;padding:0 10px;background:#ddd;height:30px;line-height:30px;text-align:center;margin-right: 5px;}
.page_list a.on{background:#015F84;color:#ffffff;}
以下内容复制到自己需要的asp文件里面
'**************************************************
'函数名:JoinChar
'作 用:向地址中加入 ? 或 &
'参 数:strUrl ----网址
'返回值:加了 ? 或 & 的网址
'**************************************************
function JoinChar(strUrl)
if strUrl = "" then
JoinChar = ""
exit function
end if
if InStr(strUrl,"?") < len(strUrl) then
if InStr(strUrl,"?") > 1 then
if InStr(strUrl,"&") < len(strUrl) then
JoinChar = strUrl & "&"
else
JoinChar = strUrl
end if
else
JoinChar = strUrl & "?"
end if
else
JoinChar = strUrl
end if
end function
'函数名:csPage1
'作 用:显示分页:首页 上一页 1 2 3 4 5 6 7 8 下一页 尾页
'参 数:strfilename ----网址
' totalnumber ----总条数
' maxperpage ----每页条数
' currentpage ----当前页
'返回值:分页html
'**************************************************
function csPage1(strfilename,totalnumber,maxperpage,currentpage)
dim n,i,strTemp,strUrl
if totalnumber mod maxperpage = 0 then
n = totalnumber \ maxperpage
else
n = totalnumber \ maxperpage + 1
end if
strUrl = JoinChar(strfilename) '向网址中加入 ? 或 &
if currentpage <> 1 then strTemp = "<a href=""" & strUrl & "page=1"">首页</a> <a href=""" & strUrl & "page=" & currentpage-1 & """>上一页</a> "
if n < 10 or currentpage < 10 then
istart = 1
if n < 10 then iend = n else iend = 10
elseif n-currentpage < 10 then
istart = n - 10
iend = n
else
istart = currentpage - 4
iend = currentpage + 5
end if
for i = istart to iend
if i = currentpage then
'strTemp=strTemp & "<span class='pnnum1'>" & i & "</span> "
strTemp = strTemp & "<a class='on' href=""" & strUrl & "page=" & i & """>" & i & "</a> "
else
strTemp = strTemp & "<a href=""" & strUrl & "page=" & i & """>" & i & "</a> "
end if
next
if currentpage <> n then strTemp = strTemp & "<a href=""" & strUrl & "page=" & currentpage+1 & """>下一页</a> <a href=""" & strUrl & "page=" & n & """>尾页</a>"
csPage1 = strTemp
end function