几种分页的写法

 1.分页效果:首页 前10  1 2 3 4 5 6 7 8 9 10  后10  尾页

<%
Dim iPageCount,i,pageStart,pageEnd
iPageCount = 30 '假设有30页
if request("display")="" then
curpage=1
else
curpage=cint(request("display"))
end if
'页数从pageStart开始
pageStart = ((curpage-1)/10)*10+1
'页数从pageEnd结束
pageEnd = pageStart + 9
'如果超过总的记录数,则pageEnd等于总记录数
if pageEnd > iPageCount Then pageEnd = iPageCount
Response.Write("第" & curpage & "/" & iPageCount & "页")
if pageStart > 1 then Response.Write("<a href=test.asp?display=" & pageStart - 10 & "><<</a>&nbsp;")
for i = pageStart to pageEnd
Response.Write("<a href='?display=" & i & "'>第" & i & "页</a> ")
next
If pageEnd < iPageCount Then Response.Write("<a href=test.asp?display=" & pageStart + 10 & ">>></a>")
%>

2.分页效果: 共有 X 篇文章 首页 前一页 后一页 尾页

 '***********************************************
'过程名:showpage
'作  用:显示“上一页 下一页”等信息
'参  数:sfilename  ----链接地址
'   totalnumber ----总数量
'   maxperpage  ----每页数量
'   ShowTotal   ----是否显示总数量
'   ShowAllPages ---是否用下拉列表显示所有页面以供跳转。有某些页面不能使用,否则会出现JS错误。
'   strUnit     ----计数单位
'***********************************************
sub showpage(sfilename,totalnumber,maxperpage,ShowTotal,ShowAllPages,strUnit)
 dim n, i,strTemp,strUrl
 if totalnumber mod maxperpage=0 then
     n= totalnumber / maxperpage
   else
     n= totalnumber / maxperpage+1
   end if
   strTemp= "<table align='center'><form name='showpages' method='Post' action='" & sfilename & "'><tr><td>"
 if ShowTotal=true then
  strTemp=strTemp & "共 <b>" & totalnumber & "</b> " & strUnit & "&nbsp;&nbsp;"
 end if
 strUrl=JoinChar(sfilename)
   if CurrentPage<2 then
      strTemp=strTemp & "首页 上一页&nbsp;"
   else
      strTemp=strTemp & "<a href='" & strUrl & "page=1'>首页</a>&nbsp;"
      strTemp=strTemp & "<a href='" & strUrl & "page=" & (CurrentPage-1) & "'>上一页</a>&nbsp;"
   end if
' Response.Write(strTemp)

   if n-currentpage<1 then
      strTemp=strTemp & "下一页 尾页"
   else
      strTemp=strTemp & "<a href='" & strUrl & "page=" & (CurrentPage+1) & "'>下一页</a>&nbsp;"
      strTemp=strTemp & "<a href='" & strUrl & "page=" & n & "'>尾页</a>"
   end if
' Response.Write(strTemp)
    strTemp=strTemp & "&nbsp;页次:<strong><font color=red>" & CurrentPage & "</font>/" & n & "</strong>页 "
    strTemp=strTemp & "&nbsp;<b>" & maxperpage & "</b>" & strUnit & "/页"
 if ShowAllPages=True then
  strTemp=strTemp & "&nbsp;转到:<select name='page'size='1'οnchange='javascript:submit()'>"  
     for i = 1 to n  
      strTemp=strTemp & "<option value='" & i & "'"
   if cint(CurrentPage)=cint(i) then strTemp=strTemp & " selected "
   strTemp=strTemp & ">第" & i & "页</option>"  
     next
  strTemp=strTemp & "</select>"
 end if
 strTemp=strTemp & "</td></tr></form></table>"
 response.write strTemp
end sub

'***********************************************
'函数名: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

调用的时候可以这样调用:

showpage strFileName,totalPut,MaxPerPage,true,false,"篇文章"

strfilename:连接文件
totalPut:记录总数
maxperpage:每页显示数量

3.比较灵活的方式,可以设定分页显示效果

'分页列表函数
'url 跳转的地址
'querry ?后的参数
'Separator 分隔符
'ListType 分页类型
'类型:0 "第一页 | 前一页 | 下一页 | 最后页"
'类型:1 "1 | 2 | 3 | 4 | ..........| 下一页"
'类型:2 "第一页 | 前十页 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 后十页 | 最后页"
'ListLink 链接使用的样式

sub PageList(ListType,url,querry,Separator,ListLink)
 if Separator="" then Separator="|"
 if ListType="" then ListType="0"
 select case ListType
  case "0"
   response.write"第"&currentpage&"/"&n&"页&nbsp;&nbsp;"
   response.write"共"&totalrec&"条信息&nbsp;&nbsp;"
   if currentpage <= 1 then
    response.write"第一页&nbsp;"&Separator&"&nbsp;"
    response.write"前一页&nbsp;"&Separator&"&nbsp;"
   else
    response.write"<a href="""&url&"?page=1&"&querry&""" class="""&ListLink&""">第一页</a>&nbsp;"&Separator&"&nbsp;"
    response.write"<a href="""&url&"?page="&currentpage-1&"&"&querry&"""  class="""&ListLink&""">前一页</a>&nbsp;"&Separator&"&nbsp;"
   end if
   if currentpage = n then
    response.write"下一页&nbsp;"&Separator&"&nbsp;"
    response.write"最后页&nbsp;"
   else
    response.write"<a href="""&url&"?page="&currentpage+1&"&"&querry&"""  class="""&ListLink&""">下一页</a>&nbsp;"&Separator&"&nbsp;"
    response.write"<a href="""&url&"?page="&n&"&"&querry&""" class="""&ListLink&""">最后页</a>&nbsp;"
   end if
  case "1"
   if currentpage < n then
    response.write"<a href="""&url&"?page="&currentpage+1&"&"&querry&""" class="""&ListLink&""">下一页</a>&nbsp;"   
   else
    response.write"下一页&nbsp;"   
   end if
   for i=1 to n
    if cstr(i)=cstr(currentpage) then
     response.write "<b>"&i&"</b>"&"&nbsp;"&Separator&"&nbsp;"
    else
     response.write"<a href="""&url&"?page="&i&"&"&querry&""" class="""&ListLink&""">"&i&"</a>&nbsp;"&Separator&"&nbsp;" 
    end if
   next
  
  case "2"
   PageMerCout=10 '每次可翻的最大页数
  '取得记录的最大页码段
  if n mod PageMerCout=0 then
   MaxPageFiled=n/PageMerCout
  else
   MaxPageFiled=n/PageMerCout+1
  end if
  '判断当前页所在的页码段
  if currentpage mod PageMerCout =0 then
   CurrPageFiled=currentpage/PageMerCout
  else
   CurrPageFiled=currentpage/PageMerCout+1
  end if
  '取得当前页码段的最大页码和最小页码
  MaxPageNo=CurrPageFiled*PageMerCout
  MinPageNo=(CurrPageFiled-1)*PageMerCout+1
  '输出 “第一页 | 前十页 |”
  if currentpage<=1 then
   response.write"第一页&nbsp;"&Separator&"&nbsp;"
  else
   response.write"<a href="""&url&"?page=1&"&querry&""" class="""&ListLink&""">第一页</a>&nbsp;"&Separator&"&nbsp;"
  end if
  if CurrPageFiled<=1 then
   response.write"前十页&nbsp;"&Separator&"&nbsp;"      
  else
   response.write"<a href="""&url&"?page="&MinPageNo-PageMerCout&"&"&querry&""" class="""&ListLink&""">前十页</a>&nbsp;"&Separator&"&nbsp;"      
  end if
  '输出当前页码段
  for i=MinPageNo to MaxPageNo
   if i<=n then
    if cstr(i)=cstr(currentpage) then
     response.write "<b>"&i&"</b>"&"&nbsp;"&Separator&"&nbsp;"
    else
     response.write"<a href="""&url&"?page="&i&"&"&querry&""">"&i&"</a>&nbsp;"&Separator&"&nbsp;" 
    end if
   end if
  next
  '输出 “后十页 | 最后页”
  if CurrPageFiled>=MaxPageFiled then
   response.write"后十页&nbsp;"&Separator&"&nbsp;"      
  else
   response.write"<a href="""&url&"?page="&MaxPageNo+1&"&"&querry&""" class="""&ListLink&""">后十页</a>&nbsp;"&Separator&"&nbsp;"      
  end if
  if currentpage>=n then
   response.write"最后页&nbsp;" 
  else
   response.write"<a href="""&url&"?page="&n&"&"&querry&""" class="""&ListLink&""">最后页</a>&nbsp;" 
  end if
 end select
end sub

4.一个比较简单的

on error resume next
'分页程序
function fy(scount,pgsize,pg,url)
'scount记录总数
'pgsize每面记录数
'pg当前页
'url转向的地址,运行本函数后会在后面加上"&page=页号"
dim pgcount,i,j,mh,k
mh=chr(34) '不好意思,是双引号


'cint()会四舍五入,所以不得不加个k
k=(scount+pgsize-1)/pgsize
pgcount=cint((scount+pgsize-1)/pgsize)
if pgcount>k then pgcount=pgcount-1

response.write "<a href="+mh+url+"&page=1"+mh+">[第一页]</a>&nbsp;"
if cint(pg)>cint(1) then
response.write "<a href="+mh+url+"&page="+cstr(pg-1)+mh+">[上一页]</a>&nbsp;"
end if
if cint(pg)>5 then
i=cint(pg)-5
else
i=1
end if

if cint(pgcount)<cint(pg+5) then
j=pgcount
else
j=pg+5
end if


while cint(i)<=cint(j)

if cint(i)=cint(pg) then
response.write cstr(i)+"&nbsp;"
else
response.write "<a href="+mh+url+"&page="+cstr(i)+mh+">"+cstr(i)+"</a>&nbsp;"
end if
i=i+1
wend

if cint(pgcount)>cint(pg) then
response.write "<a href="+mh+url+"&page="+cstr(pg+1)+mh+">[下一页]</a>&nbsp;"
end if

response.write "<a href="+mh+cstr(url)+"&page="+cstr(pgcount)+mh+">[最后页]</a>&nbsp;"

end function

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值