asp模組化分頁製作詳解

來源:互聯網
上載者:User

模組化分頁

1.查詢語句塊

<%
取得當前檔案名稱
temp = Split(request.ServerVariables("URL"), "/")
fy = temp(UBound(temp))
set rs=server.createobject("adodb.recordset")
if not isempty(request("page")) then  
pagecount=cint(request("page"))  
else  
pagecount=1  
end if
sql="select  查詢語句"
rs.open sql,conn,1,1
rs.pagesize=10  分頁記錄數
if pagecount>rs.pagecount or pagecount<=0 then             
pagecount=1             
end if            
if rs.eof and rs.bof then%>

<div align="center" class="001"><br>
對不起,沒有符合搜尋條件的記錄!<br>
</div>

2.顯示記錄塊

<%
else
rs.AbsolutePage=pagecount
do while not rs.eof %>

顯示的記錄

<% i=i+2
rs.movenext
if i>=rs.PageSize then exit do
loop
'www.knowsky.com
%>

3.
分頁效果
<table width="778" border="0" align="center" cellpadding="0" cellspacing="0">
<tr align="center">
    <% if rs.pagecount=1 then %>
    <td height="35" colspan="4" class=001><font color="#000000">共有[<font color="#ff0000"><%=rs.recordcount%></font>]條資訊 當前顯示第 <font color="red">1~<%=rs.recordcount%></font>條</font></td>
  </tr>
  <tr>
    <%else%>
    <td width="19%" height="35" align="center" valign="middle" class=001><font color="#000000">
      <% page_start=(pagecount-1)*rs.pagesize
            if pagecount=1 then page_start=1
      page_end=rs.pagesize*pagecount
      if pagecount*rs.pagesize=>rs.recordcount then page_end=rs.recordcount end if%>
      共有[<font color="#ff0000"><%=rs.recordcount%></font>]資訊</font></td>
    <td width="58%" height="30" align="center" class="fy"><font color="#000000">
          <%
    if pagecount>5 and pagecount< rs.PageCount-5 and rs.pagecount>10 then
    qizu=pagecount-4
    min=pagecount+5
    response.write"<a href="&source&"?page=1&sortid="&sortid&"&typeid="&typeid&"&qylb="&qylb&"&title="&title&"&cityid="&cityid&">
<font color='0000BE'>首頁</font></a> "
    response.write"<a href="&source&"?page="+cstr(pagecount-1)+"&sortid="&sortid&"&typeid="&typeid&"&qylb="&qylb&"&title="&title&"&cityid="&cityid&">
<font color='0000BE'>上一頁</font></a> "
    for ipage=qizu to min
             if ipage<>pagecount then
             response.write"<a href="&source&"?page="+cstr(ipage)+"&sortid="&sortid&"&typeid="&typeid&"&qylb="&qylb&"&cityid="&cityid&"><font color='0000BE'>"+cstr(ipage)+"</font></a> "
             else
             response.write "<font color='#FF0000'>"&ipage&"</font> "
             end if
    next
    response.write"<a href="&source&"?page="+cstr(pagecount+1)+"&sortid="&sortid&"&typeid="&typeid&"&qylb="&qylb&"&title="&title&"&cityid="&cityid&">
<font color='0000BE'>下一頁</font></a> "
    response.write"<a href="&source&"?page="+cstr(rs.PageCount)+"&sortid="&sortid&"&typeid="&typeid&"&qylb="&qylb&"&title="&title&"&cityid="&cityid&">
<font color='0000BE'>尾頁</font></a>"
    end if
    if rs.PageCount<11 then
    for ipage=1 to rs.PageCount
             if ipage<>pagecount then
             response.write"<a href="&source&"?page="+cstr(ipage)+"&sortid="&sortid&"&typeid="&typeid&"&qylb="&qylb&"&cityid="&cityid&"><font color='0000BE'>"+cstr(ipage)+"</font></a> "
             else
             response.write "<font color='#FF0000'>"&ipage&"</font> " 
             end if
    next
    end if
    if pagecount < 6 and rs.PageCount>10 then
    for ipage=1 to 10
             if ipage<>pagecount then
             response.write"<a href="&source&"?page="+cstr(ipage)+"&sortid="&sortid&"&typeid="&typeid&"&qylb="&qylb&"&cityid="&cityid&"><font color='0000BE'>"+cstr(ipage)+"</font></a> "
             else
             response.write "<font color='#FF0000'>"&ipage&"</font> "      
             end if
    next
    response.write "<a href="&source&"?page="+cstr(rs.PageCount)+"&sortid="&sortid&"&typeid="&typeid&"&qylb="&qylb&"&title="&title&"&cityid="&cityid&">
<font color='0000BE'>尾頁</font></a>"
    end if
    if pagecount>rs.PageCount-6 and rs.PageCount>10 then
    response.write "<a href="&source&"?page=1&sortid="&sortid&"&typeid="&typeid&"&qylb="&qylb&"&title="&title&"&cityid="&cityid&">
<font color='0000BE'>首頁</font></a> "  
    for ipage=rs.PageCount-9 to rs.PageCount
             if ipage<>pagecount then
             response.write"<a href="&source&"?page="+cstr(ipage)+"&sortid="&sortid&"&typeid="&typeid&"&qylb="&qylb&"&cityid="&cityid&"><font color='0000BE'>"+cstr(ipage)+"</font></a> "
             else
             response.write "<font color='#FF0000'>"&ipage&"</font> "
             end if
    next
    end if
             %>
    </font></td><form name=go2to form method=Post action=<%=fy%>> 
    <td width="13%" align="center" valign="middle" class="fy">
   <input type='hidden' name='sortid' value="<%=sortid%>"><input type='hidden' name='typeid' value="<%=typeid%>"><input type='hidden' name='qylb' value="<%=qylb%>"><input type='hidden' name='title' value="<%title%>"><input type='hidden' name='cityid' value="<%=cityid%>"><font color='000064'> 轉到第<input type='text' name='page' size=2 maxLength=3>
   頁</font>                              
   </td>
    <td width="10%" align="center" valign="middle" class="fy"><input name="image" type='image' onClick=check() value='確 定' src='http://edu.cnzz.cn/images/button_h.jpg'></td>
    </form>
  <tr>
    <td height="20" colspan="6" valign="bottom"><font color="#000000">  </font></td>
  </tr>
  <% end if %>
  <% end if %>
</table>



聯繫我們

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