ASP通用分頁的實現

來源:互聯網
上載者:User

自己寫的通用分頁,可設定顯示的分頁連結數,帶下拉選擇:

1<%2'Written by Shaoyun 20:17 2008年5月29日 0:383'Email:shaoyun at yeah.net4'Blog:http://shaoyun.cnblogs.com5'分頁函數:splitpage(記錄總數,每頁顯示記錄數,顯示幾條分頁連結)6Function splitpage(rscount,pagesize,shownum)78Dim pagenum,curpage,first_page,last_page,up_page,down_page,idx,addr_url,splitpage_html910addr_url=Request.ServerVariables("URL")11addr_url=Mid(addr_url,InstrRev(addr_url,"/")+1)12addr_url=addr_url & "?page="1314if (rscount mod pagesize)=0 then15  pagenum=rscount/pagesize16else17  pagenum=rscount/pagesize+118end if19first_page=120last_page=pagenum2122curpage=123if isnumeric(trim(request.QueryString("page"))) then24  curpage=trim(request.QueryString("page"))25  if pagenum-curpage<0 then curpage=pagenum26else27  curpage=128end if2930up_page=curpage-131down_page=curpage+13233splitpage_html="共$rscount$條記錄&nbsp;$pagesize$條/頁&nbsp;第$curpage$/$pagenum$頁&nbsp;"34splitpage_html=replace(splitpage_html,"$rscount$",rscount)35splitpage_html=replace(splitpage_html,"$pagesize$",pagesize)36splitpage_html=replace(splitpage_html,"$curpage$",curpage)37splitpage_html=replace(splitpage_html,"$pagenum$",pagenum)3839splitpage_html=splitpage_html & "<a href='" & addr_url & first_page & "'>首頁</a>&nbsp;"40if curpage>1 then41  splitpage_html=splitpage_html & "<a href='" & addr_url & up_page & "'>上一頁</a>&nbsp;"42else43  splitpage_html=splitpage_html & "上一頁&nbsp;"44end if4546dim fbegin,fend47if shownum mod 2 then48  show_front_num=int(shownum/2)49  show_back_num=int(shownum/2)50else51  show_front_num=int(shownum/2)-152  show_back_num=int(shownum/2)53end if54if curpage-1<show_front_num then55  fbegin=156  fend=shownum57elseif curpage+show_back_num>pagenum then58  fend=pagenum59  fbegin=pagenum-shownum+160else61  fbegin=curpage-show_front_num62  fend=curpage+show_back_num63end if64for idx=fbegin to fend65  if curpage-idx=0 then66    splitpage_html=splitpage_html & "<b>" & idx & "</b>&nbsp;"67  else68    splitpage_html=splitpage_html & "<a href='" & addr_url & idx & "'>" & idx & "</a>&nbsp;"69  end if70next7172if pagenum-curpage>0 then73  splitpage_html=splitpage_html & "<a href='" & addr_url & down_page & "'>下一頁</a>&nbsp;"74else75  splitpage_html=splitpage_html & "下一頁&nbsp;"76end if77splitpage_html=splitpage_html & "<a href='" & addr_url & last_page & "'>尾頁</a>&nbsp;"7879splitpage_html=splitpage_html & "跳轉到&nbsp;"80splitpage_html=splitpage_html & "<select onChange=window.location.href=this.options[this.selectedIndex].value>"81For idx=1 To pagenum82  If curpage-idx=0 Then83    splitpage_html=splitpage_html & "<option value='" & addr_url & idx & "' selected>第" & idx & "頁</option>"84  Else85    splitpage_html=splitpage_html & "<option value='" & addr_url & idx & "'>第" & idx & "頁</option>"86  End if87Next88splitpage_html=splitpage_html & "</select>"8990response.Write splitpage_html9192End Function93%>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.