Chào mừng bạn đến với Diễn Đàn Máy Chủ - Chia sẽ kiến thức máy chủ.
  • Đăng ký
    • Login:
    Server Dell email 247 Tên miền Hosting giá sốc Tang loa Frei Tang loa Frei Tên miền tiếng việt giá bèo cdn rẻ vô địch May Chu Khong Lo - Gia Xi Trum SSL 2 nam giam 15%
    + Trả lời bài viết
    Hiện kết quả từ 1 tới 2 của 2

    Chủ đề: Phân trang trong ASP

    1. #1
      Advisors
      Tham gia ngày
      Aug 2009
      Đến từ
      Nha Trang
      Bài gửi
      1.287

      Mặc định Phân trang trong ASP

      Phân tran trong ngôn ngữ lập trình ASP.
      <%@LANGUAGE=VBScript%>
      <%
      ‘ Define variables
      dim recordsonpage, requestrecords, offset, allrecords, hiddenrecords, showrecords, lastrecord, recordcounter, pagelist, pagelistcounter

      ‘ DB connection
      dim Conn
      Set Conn = Server.CreateObject(”ADODB.Connection”)
      sConnection = “Provider=Microsoft.Jet.OLEDB.4.0;” & _
      “Data Source=” & Server.MapPath(”cddatabase.mdb”) & “;” & _
      “Persist Security Info=True”
      Conn.Open(sConnection)

      ‘ records per page
      recordsonpage = 10

      ‘ count all records
      allrecords = 0
      set rs = conn.Execute(”SELECT * FROM cds”)
      do until rs.EOF
      allrecords = allrecords + 1
      rs.movenext
      loop

      ‘ if offset is zero then the first page will be loaded
      offset = request.querystring(”offset”)
      if offset = 0 OR offset = “” then
      requestrecords = 0
      else
      requestrecords = requestrecords + offset
      end if

      ‘ opens database
      set rs = conn.Execute(”SELECT * FROM cds ORDER BY cdid”)

      ‘ reads first records (offset) without showing them (can’t find another solution!)
      hiddenrecords = requestrecords
      do until hiddenrecords = 0 OR rs.EOF
      hiddenrecords = hiddenrecords – 1
      rs.movenext
      if rs.EOF then
      lastrecord = 1
      end if
      loop
      %>


      <%
      ‘ prints records in the table
      showrecords = recordsonpage
      recordcounter = requestrecords
      do until showrecords = 0 OR rs.EOF
      recordcounter = recordcounter + 1
      %>


      <%
      showrecords = showrecords – 1
      rs.movenext
      if rs.EOF then
      lastrecord = 1
      end if
      loop
      %>


      <% = recordcounter %> <% = rs(”cdid”) %> <% = rs(”title”) %>
      <% if requestrecords <> 0 then %>Prev Page<% else %>Prev Page<% end if %> <% if lastrecord <> 1 then %> Next Page<% else %>Next Page<% end if %>
      pagelist:
      <%
      pagelist = 0
      pagelistcounter = 0
      do until pagelist > allrecords
      pagelistcounter = pagelistcounter + 1
      %>
      <% = pagelistcounter %>
      <%
      pagelist = pagelist + recordsonpage
      loop
      %>


      <%
      ‘ Closes connection
      rs.close
      Conn.close
      %>

      Các bạn có thể download code hoàn chỉnh tại đây http://www.encysoft.com/download/paging.txt

    2. #2
      Thành Viên Mới
      Tham gia ngày
      Feb 2018
      Bài gửi
      1

      Mặc định

      Bác trên còn spam luôn trong bài của Smod ạ, quỳ!

     

     
    + Trả lời bài viết

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

    Quyền viết bài

    • Bạn không thể gửi chủ đề mới
    • Bạn không thể gửi trả lời
    • Bạn không thể gửi file đính kèm
    • Bạn không thể sửa bài viết của mình