熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

asp分頁程序

2022-06-13   來源: .NET編程 

  <%@language="vbscript" codepage=""%>
<%
定義數據連接
option explicit
on error resume next
dim startimeendtime
startime=timer()
dim dbconnrs
db = "provider=microsoftjetoledb;data source=" & servermappath("/dbmdb")
set conn = servercreateobject("adodbconnection")
set rs = servercreateobject("adodbrecordset")
connopen db
%>
<%
**************
分頁導航欄函數
輸出wzpage值
**************
Function pagination(pagecount)
   Dim wzpagewzpagecountpagenumboardid
   boardid = RequestQueryString("board_id")
   If boardid = Then boardid =
       If Len(RequestQueryString("page"))<> Then
          wzpage = clng(RequestQueryString("page"))
         Else
          wzpage =
       End If
       If wzpage <= Then wzpage =
       pagenum = (wzpage )*+
       If wzpage mod = Then pagenum = (wzpage )*
       If wzpage > Then
         ResponseWrite ("<font face=""webdings"">")
            ResponseWrite ("<a href=""?board_id="& boardid &"&page="" title=""首頁""></a>")
   ResponseWrite ("<a href=""?board_id="& boardid &"&page="& pagenum &""" title=""前十頁""></a>")
            ResponseWrite ("</font>")
    End If
       For pagenum = pagenum To pagenum +
           If pagenum = wzpage Then
                  ResponseWrite ("<font color=""#ff"">")
                  ResponseWrite (" ["& pagenum &"] ")
                  ResponseWrite ("</font>")
        Else
                  ResponseWrite (" <a href=""?board_id="& boardid &"&page="& pagenum &""">")
                  ResponseWrite ("["& pagenum &"]")
                  ResponseWrite ("</a> ")
   End If
         If pagenum >= pagecount Then Exit For
       Next
     If wzpage < (pagecount (pagecount ))  Then
         ResponseWrite ("<font face=""webdings"">")
            ResponseWrite ("<a href=""?board_id="& boardid &"&page="& pagenum &"""  title=""後十頁""></a>")
   ResponseWrite ("<a href=""?board_id="& boardid &"&page="& pagecount &"""  title=""末頁"">:</a>")
            ResponseWrite ("</font>")
   End If
End Function
%>
<%
dim rssqlgetstring
getstring = clng(requestquerystring("board_id"))
if getstring = then getstring =

  ******************************************
取文章總數及每頁重復顯示條數准備分頁
wzcount 文章總數
wzrep 重復顯示條數
wzpage 分頁參數id
wzpagecount 總頁數
******************************************
dim wzcountwzrepwzpagewzpagecountwzpagerepboardstr
wzrep =
rssql = "select count(id) from `table`"
rsopen rssqlconn&h
wzcount = connexecute ("select count(id) from `table`")()
rsclose
wzpagecount = abs(int(abs(wzcount/wzrep)))
wzpage = clng(requestquerystring("page"))
if len(wzpage) = or wzpage = then wzpage =

  %>
<html>
<head>
<title>分頁測試</title>
<meta httpequiv="contenttype" content="text/html; charset=gb">
<link rel="stylesheet" href="pagecss" type="text/css">
</head>
<body>
<table width="" border="" cellspacing="" cellpadding="" align="center" bordercolordark="#ffffff" bordercolorlight="#cccccc">
  <tr align="center">
    <td width="">ID</td>
    <td width="">標題</td>
    <td width="*">內容(顯示前個字)</td>
    <td width="">時間</td>
  </tr>
  <%
取文章列表
rssql = "select idaaaabbbbcccc from `table` order by id desc"
rsopen rssqlconn&h
根據分頁參數獲取當前頁面紀錄
rsabsoluteposition=rsabsoluteposition+((abs(wzpage))*wzrep)
顯示文章標題列表
if rseof or rsbof then%>
<tr>
    <td >暫無記錄</td>   
  </tr>
<% else
dim ibgcolor
for i = to wzrep
 if rseof then exit for
while not rseof and i <= wzrep
 bgColor="#FFFFFF"
 if i mod = then bgColor="#DFEFFF"
%>
  <tr bgcolor="<%=bgColor%>">
    <td width=""><%=rs()%></td>
    <td width=""><%=rs()%></td>
    <td width="*"><%=left(rs())%></td>
    <td width=""><%=rs()%></td>
  </tr>
<%
rsmovenext
i=i+
wend
next
end if
%>
</table>
<table width="" border="" cellspacing="" cellpadding="" align="center">
  <tr>
    <td align="left" width="">共<font color=red><%= wzcount%></font>條 <font color=red><%= wzrep%></font>/頁 共<font color=red><%= wzpagecount%></font>頁</td>
 <td align="right"> <%= pagination(wzpagecount)%></td>
  </tr>
</table>
 
<table width="" border="" align="center" cellpadding="" cellspacing="">
  <tr>
    <td align="center">
      <%endtime=timer()%>
      本頁面執行時間<%=formatnumber((endtimestartime)*)%>毫秒</td>
  </tr>
</table>
</body>
</html>
<%
釋放資源
rsclose
set rs = nothing
connclose
set conn = nothing
%>


From:http://tw.wingwit.com/Article/program/net/201311/14352.html
  • 上一篇文章:

  • 下一篇文章:
  • 推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.