自己整理的一个ASP分页的代码测试文件

<!--#include file="conn.inc"-->

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
.style3 {font-size: 10px}
-->
</style>
</head>

<body>
<%
szSQL="select * from qq"
set oCon=server.CreateObject("ADODB.connection")
oCon.ConnectionString=m_DBConnectionString
oCon.CursorLocation=3
oCon.Open
set oRs=server.CreateObject("ADODB.Recordset")
set oRs.ActiveConnection=oCon
oRs.Open szSQL
set oRs.ActiveConnection=nothing


'分页 AbsolutePage:指定当前的页; PagePount: 返回记录集中的逻辑页数 PageSize:指定一个逻辑页中的记录个数,缺省值是10
CurrentPage = trim(Request("CurrentPage"))
if CurrentPage="" or CurrentPage="NaN" then
CurrentPage=1
end if
CurrentPage = CInt(CurrentPage)

oRs.PageSize =5
nTotal=ors.RecordCount

if nTotal > 0 then
if nTotal mod oRs.PageSize = 0 then
PageCount = Int(nTotal / oRs.PageSize)
else
PageCount = Int(nTotal / oRs.PageSize) + 1
end if
elseif nTotal = 0 then
PageCount = 0
CurrentPage = 0
end if
oRs.AbsolutePage=CurrentPage
%>
   
<table width="500" border="0" align="center" cellpadding="0" cellspacing="2" bgcolor="#999999">
<tr bgcolor="#FFFFFF">
<td width="245" bgcolor="#00FF00">ID</td>
<td width="249" bgcolor="#00FF00">Name</td>
</tr>
<%
m=0
do while not oRs.eof
id=oRs("CertCateId")
name=oRs("CertName")
%>
<tr bgcolor="#FFFFFF">
<td><% response.Write(id)%></td>
<td><% response.Write(Name)%></td>
</tr>
<%
m=m+1
oRs.movenext
if m>=oRs.PageSize then exit do
loop
oRs.close
set oRs=nothing
%>
</table>
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><p class="style1"><a href="testAspSql_exe.asp?op=add">添加 </a> 当前页/总页数:<font style='color:#FF0000;'><%=CurrentPage%>/<%=PageCount%></font>共有<font style='color:#0000FF;'>[<%=nTotal%>]</font>条记录 <br>
<%
if CurrentPage = 1 and PageCount > 1 then
Response.Write "<a href='javascript:void(Goto(" & CurrentPage+1 & "))'>后页</a>&nbsp;"
Response.Write "<a href='javascript:void(Goto(" & PageCount & "))'>尾页</a>"
elseif CurrentPage <> 1 and CurrentPage = PageCount then
Response.Write "<a href='javascript:void(Goto(1))'>首页</a>&nbsp;"
Response.Write "<a href='javascript:void(Goto(" & CurrentPage-1 & "))'>前页</a>"
elseif CurrentPage > 1 and CurrentPage < PageCount and CurrentPage > 0 then
Response.Write "<a href='javascript:void(Goto(1))'>首页</a>&nbsp;"
Response.Write "<a href='javascript:void(Goto(" & CurrentPage-1 & "))'>前页</a>&nbsp;"
Response.Write "<a href='javascript:void(Goto(" & CurrentPage+1 & "))'>后页</a>&nbsp;"
Response.Write "<a href='javascript:void(Goto(" & PageCount & "))'>尾页</a>"
end if
%>
</p></td>
</tr>
</table>
</body>
</html>
<script language="JavaScript" type="text/JavaScript">
//================跳转到某一页====================//
function Goto(nPage)
{
if(nPage=="")
{alert("请输入页码");return;}
window.location= "testAspSql.asp?CurrentPage="+nPage;//+"&IsSearch=<%=nIsSearch%>";
//document.ListForm.submit();
}

</script>

'//---------conn.inc文件-----//
<%
m_DBConnectionString = "Driver={SQL Server};Server=localhost;UID=sa;PWD=admin;Database=test"
set oCon=server.CreateObject("ADODB.connection")
oCon.ConnectionString=m_DBConnectionString
oCon.CursorLocation=3
oCon.Open
%>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值