国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Asp用于分頁的兩個函數

2019-11-18 19:09:15
字體:
來源:轉載
供稿:網友

(原創 vince6799)
asp代碼中分頁是有點麻煩的事情,個人在在代碼編寫過程中把分頁代碼寫成了兩個函數,雖然在功能上不是很完善,但對于一般的應用應該是滿足的了。

<%
'分頁函數分為兩個函數
'CalcPage(totalrec,msg_per_page,currentpage,n,rowcount,PageRs) 分頁計算函數
'PageList(ListType,url,querry,Separator,ListLink) 分頁列表函數

'分頁計算函數
'totalrec 記錄集總數
'msg_per_page 每頁顯示的記錄數,在調用CalcPage時需提前對該變量賦值
'currentpage 當前頁變量,在調用CalcPage時需提前對該變量賦值
'n 總頁數 
'rowcount 設置每一頁的數據記錄數
'PageRs 記錄集對象
sub CalcPage(totalrec,msg_per_page,currentpage,n,rowcount,PageRs)
 n=0 '設置無記錄時頁數為0
 if currentpage="" then currentpage=0
 'PageRs.EOF and PageRs.bof  無記錄
 'Not PageRs.EOF Or Not PageRs.BOF 有記錄
 if Not PageRs.EOF Or Not PageRs.BOF then
  totalrec=PageRs.recordcount
  PageRs.pagesize=msg_per_page
  if totalrec mod msg_per_page = 0 then '計算總頁數,recordcount:數據的總記錄數
   n = totalrec/msg_per_page 'n:總頁數
  else
   n = totalrec/msg_per_page+1
  end if
  if not isnumeric(currentpage) or currentpage="" then currentpage=1
  If currentpage <> "" then
   currentpage = cint(currentpage)
  end if
  if currentpage < 1 then
   currentpage = 1
  end if
  if currentpage*msg_per_page > totalrec and not((currentpage-1)*msg_per_page < totalrec) then
   currentPage=1
  end if
  PageRs.absolutepage = currentpage 'absolutepage:設置指針指向某頁開頭
  rowcount = PageRs.pagesize            'pagesize:設置每一頁的數據記錄數
 end if
end sub
%>
<%
'分頁列表函數
'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
%>


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 江门市| 织金县| 施秉县| 宝鸡市| 锡林浩特市| 留坝县| 绵竹市| 高唐县| 都匀市| 沙坪坝区| 滨海县| 柳林县| 德惠市| 邢台市| 竹北市| 和田市| 连平县| 宁安市| 景东| 大悟县| 西峡县| 嘉荫县| 嘉定区| 蕲春县| 锦屏县| 拜城县| 承德市| 广平县| 辽源市| 乌苏市| 温泉县| 宜章县| 夏河县| 青河县| 益阳市| 甘德县| 来安县| 澄城县| 华坪县| 仁化县| 荔波县|