asp萬用分頁程式碼_應用技巧

來源:互聯網
上載者:User

這隻是個asp小技巧類的東西,它雖然適合在每個不同檔案名稱裡調用這個函數,但是也是有前提的,下面讓我們來仔細看看其中的原委。
下面這段是基本的分頁代碼:

<% sql = "select……………………省略了sql語句 Set rs=Server.Createobject("ADODB.RECORDSET") rs.Open sql, conn, 1, 1 if not rs.eof then  pages = 30 '定義每頁顯示的記錄數  rs.pageSize = pages '定義每頁顯示的記錄數  allPages = rs.pageCount'計算一共能分多少頁  page = Request.QueryString("page")'通過瀏覽器傳遞的頁數  'if語句屬於基本的排錯處理  if isEmpty(page) or Cint(page) < 1 then   page = 1  elseif Cint(page) > allPages then   page = allPages  end if  rs.AbsolutePage = page  Do while not rs.eof and pages > 0 %>   這裡輸出你要的內容………………   <% pages = pages - 1   rs.MoveNext  Loop else  Response.Write("資料庫暫無內容!") End if rs.Close Set rs = Nothing %>

系統已經為資料分頁了,下面就看看這次探討的關鍵問題分頁函數的定義

<% SUB pageUrl(pUrl) Dim eUrl txts = Request.ServerVariables("URL") txts = left(txts,instrrev(txts,"/",len(txts))-1) eUrl = "http://"; & Request.ServerVariables("server_name") & txts For i =1 to allpages  txt = ""  txt = "<strong>"  txt = txt & "<a href=" & eUrl & pUrl & "page="&i & ">"  if i = Cint(Page) then txt = txt & "<font color='bb0000'>"   txt = txt & (i)   if i = Cint(Page) then txt = txt & "</font>"    txt = txt & "</a> ∥ </strong>"    Response.Write(txt) NextEND sub %>

把上面這個分頁函數代碼copy存成一個ASP檔案,在需要使用的頁面裡用include來引入他調用的時候只要Call("/你調用的檔案名稱?")就ok了,比如我的 news頁面裡要調用那麼就是<%Call("/news.asp?")%>
剛才我們所到這是有限制的意思就是說第一段代碼裡除了sql查詢內容和輸出內容可以更改,其他的聲明記錄集的對象,page, pages, allpages這些變數都不能更改,否則將無法運行~其實這個程式是無關緊要的,最主要的就是,這個分頁函數可以在任何一個asp葉面裡調用。

分頁做的還不是很漂亮,高手們可以修改修改,互相切磋學習!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.