ASP分页代码 

<!--#include file="Conn.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>ASP分页程序</title>
<link href="Style/default.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
a:visited{
color:#0000CC;
text-decoration:none
}
a:hover,.red{
color:#FF0000;
}
.sitelist td{
font-size:12px;
line-height:25px;
}
-->
</style>
</head>
<body>
<div class="searchbody">
 <table width="100%" border="0" cellspacing="1" cellpadding="0">
  <tr bgcolor="#EFEFEF" align="center">
   <td width="45%" height="25"><strong>ID</strong></td>
   <td><strong>名称</strong><strong>站长</strong><strong>详情 评论 报错 更多 收藏</strong></td>
  </tr>
  <tr bgcolor="#E7E3E7">
   <td height="1" colspan="2"></td>
  </tr>
 </table>
 <table width="100%" border="0" cellspacing="0" cellpadding="0" class="sitelist">
<%
Dim sqlStr,sqlStrCount,sqlOrder,sqlCondition,rsCount,strTableName,strIDName,strQuery,strBgColor
Dim strPageName,intPageSize,intTotalNum,intTotalPage,intCurrentPage,i

strPageName  = "Page.asp" '页面名称
strTableName = "Table"  '表名
strIDName  = "ID"   '主键名
sqlCondition = ""   '查询条件
strQuery  = ""   '分页URL条件字符串
strBgColor  = Array("#FFFFFF", "#E5ECF9")


If sqlOrder  = "" Then sqlOrder = " ORDER BY "&strIDName&" DESC" '保证主表与子表排序一致

If sqlCondition = "" Then
 sqlStrCount = "SELECT COUNT("&strIDName&") AS TotalNum FROM "&strTableName
Else
 sqlStrCount = "SELECT COUNT("&strIDName&") AS TotalNum FROM "&strTableName&" WHERE "&sqlCondition
End If
Set rsCount = conn.Execute(sqlStrCount)

intPageSize = 20'每页显示的记录数
intTotalNum = rsCount("TotalNum")

If intTotalNum <> 0 Then

 intTotalPage = Fix(intTotalNum / intPageSize)

 If intTotalNum Mod intPageSize > 0 Then intTotalPage = intTotalPage + 1
 intCurrentPage = Request("intMePage")

 If intCurrentPage = "" Then
  intCurrentPage = 1
 ElseIf Not IsNumeric(intCurrentPage) Then
  intCurrentPage = 1
 Else
  intCurrentPage = CInt(intCurrentPage)
 End If

 If intCurrentPage > intTotalPage Then
  intCurrentPage = intTotalPage
 ElseIf intCurrentPage < 1 Then
  intCurrentPage = 1
 End If

 If sqlCondition = "" Then
  sqlStr = "SELECT TOP "&intPageSize&" * FROM "&strTableName&" WHERE ("&strIDName&" NOT IN(SELECT TOP "&(intPageSize * (intCurrentPage - 1))&" "&strIDName&" FROM "&strTableName&" "&sqlOrder&"))"&sqlOrder
 Else
  sqlStr = "SELECT TOP "&intPageSize&" * FROM "&strTableName&" WHERE "&sqlCondition&" AND ("&strIDName&" NOT IN(SELECT TOP "&(intPageSize * (intCurrentPage - 1))&" "&strIDName&" FROM "&strTableName&" WHERE "&sqlCondition&sqlOrder&"))"&sqlOrder
 End If
 Set rs = conn.Execute(sqlStr)
 
 i = 0
 While Not rs.EOF
%>
  <tr bgcolor="<%=strBgColor(i mod 2)%>">
   <td width="47%" height="25"><%=rs(0)%></td>
   <td><%=rs(1)%></td>
  </tr>
  
<%
  rs.MoveNext
  i = i + 1
 Wend
 Call closeRs(rs)
Else 
%>
<div align="center">没有查找到相关数据!</div>
<%
End If
Call closeConn()
%>
  <tr>
   <td colspan="2"><%Call Page()%></td>
  </tr>
 </table>
</div>
<%

Sub Page()
%>
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
 <form id="frmPage" name="frmPage" method="get" action="<%=strPageName%>?<%=strQuery%>">
  <tr>
   <td bgcolor="#FFFFFF">共<span class="redbold"><%=intTotalNum%></span>条记录 页次<span class="redbold"><%=intCurrentPage%></span>/<span class="redbold"><%=intTotalPage%></span> 每页<span class="redbold"><%=intPageSize%></span>条 <a href="<%Response.Write(strPageName&"?intMePage=1"&strQuery)%>">首页</a>
<%
If intCurrentPage > 1 Then
%>
    <a href="<%Response.Write(strPageName&"?intMePage="&intCurrentPage - 1&strQuery)%>">上页</a>
<%
End If
If intCurrentPage < intTotalPage Then
%>
    <a href="<%Response.Write(strPageName&"?intMePage="&intCurrentPage + 1&strQuery)%>">下页</a>
<%
End If
%>
    <a href="<%Response.Write(strPageName&"?intMePage="&intTotalPage&strQuery)%>">尾页</a> 跳至
    <input class="pageform" name="intMePage" type="text" id="intMePage" size="2" />
    页
    <input class="pagego" name="btnGO" type="submit" id="btnGO" value="GO" />
   </td>
  </tr>
 </form>
</table>
<%
End Sub
%>
</body>
</html>

posted @ 2005-03-19 16:05  PENGHAO-X  阅读(2614)  评论(1编辑  收藏  举报