📄 asppage.asp
字号:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
Response.Expires = 0
'************** 更改数据库名字 **************
db="test.mdb"
Set Conn = Server.CreateObject("ADODB.Connection")
ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)
'如果你的服务器采用较老版本Access驱动,请用下面连接方法
'ConnStr = "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(db)
Conn.Open ConnStr
'************** 关闭数据连接 **************
function CloseDatabase
Conn.close
Set Conn = Nothing
End Function
set rs=server.CreateObject("ADODB.recordset")
rs.open "select * from test order by id desc",conn,1,1
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>分页程序</title>
<style type="text/css">
<!--
body {
font-family: "宋体";
font-size: 12px;
}
table {
font-family: "宋体";
font-size: 12px;
}
-->
</style>
<style type="text/css">
<!--
a:link {
font-family: "宋体";
font-size: 12px;
color: #000000;
text-decoration: none;
}
a:visited {
font-family: "宋体";
font-size: 12px;
color: #000000;
text-decoration: none;
}
a:hover {
font-family: "宋体";
font-size: 12px;
color: #993300;
text-decoration: none;
}
a:active {
font-family: "宋体";
font-size: 12px;
color: #000000;
text-decoration: none;
}
-->
</style>
</head>
<body>
<%
'---------------------------------------开始分页程序
'欢迎使用蟑螂分页
const filename = "asppage.asp"'此文件的文件名
const sizepage = 20'设置每页记录数
const dispage = 10'设置页面上显示多少页
if rs.eof and rs.bof then%>
<div align="center"> <br>
没有找到任何记录</div>
<%else
RS.PageSize = sizepage
Dim TotalPages
TotalPages = RS.PageCount
if Not isnumeric(Request.QueryString("CurPage")) or Request.QueryString("CurPage") = "" Then
CurPage = 1
Elseif Cdbl(Request.QueryString("CurPage")) > TotalPages Then
CurPage = TotalPages
Else
CurPage = Cint(Request.QueryString("CurPage"))
End If
Rs.AbsolutePage=CurPage
rs.CacheSize = RS.PageSize'设置最大记录数
Dim Totalcount
Totalcount =RS.recordcount
StartPageNum=1
do while StartPageNum+dispage<=CurPage
StartPageNum=StartPageNum+dispage
Loop
EndPageNum=StartPageNum+dispage-1
If EndPageNum>RS.Pagecount then EndPageNum=RS.Pagecount%>
<table width="100%" border="0">
<tr>
<td width="153" bgcolor="#CCCCCC"><div align="center">ID</div></td>
<td width="544" bgcolor="#CCCCCC"><div align="center">主体</div></td>
</tr>
<%I=0
p=RS.PageSize*(Curpage-1)
do while (Not RS.Eof) and (I<RS.PageSize)
p=p+1%>
<tr>
<td><%=rs(0)%></td>
<td><%=rs(1)%></td>
</tr>
<%I=I+1
RS.MoveNext
Loop%>
<tr>
<td height="45" colspan="2">
<div align="right">
<form name="form1" method="get" action="<%=filename%>">
<table width="100%" border="0" align="center">
<tr>
<td width="36%" height="20">页次:<b><font color="#FF0000"><%=CurPage%></font>/<%=TotalPages%></b>
每页<b><%=sizepage%></b> 总记录数<b><%=rs.recordcount%></b></td>
<td width="64%"><div align="right">分页:<%if CurPage>dispage then%><a href="<%=filename%>?CurPage=1"><font face=webdings title="首页">9</font></a>
<%end if%>
<%if CurPage>dispage then%>
<a href="<%=filename%>?CurPage=<%=StartPageNum-1%>"><font face=webdings title="上<%=dispage%>页">7</font></a>
<%end if
For I=StartPageNum to EndPageNum
if I<>CurPage then %>
<a href="<%=filename%>?CurPage=<%=I%>"><b><%=I%></b></a>
<% else %>
<font color="#FF0000"><b><%=I%></b></font>
<% end if
Next %>
<% if EndPageNum<RS.Pagecount then %>
<a href="<%=filename%>?CurPage=<%=EndPageNum+1%>"><font face=webdings title="下<%=dispage%>页">8</font></a>
<%end if
if CurPage<TotalPages then%>
<a href="<%=filename%>?CurPage=<%=TotalPages%>"><font face=webdings title="尾页">:</font></a>
<%end if%>
转到:
<input name="CurPage" type="text" id="CurPage" value="<%=CurPage%>" size="3" maxlength="10">
<input type="submit" name="Submit" value="GO">
</div></td>
</tr>
</table>
</form>
</div></td>
</tr>
</table>
<%
end if
rs.close
set rs=nothing
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -