asp分页(自己整理的2个分页程序)
<%@language="vbscript" codepage="936"%>
<!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>
<style type="text/css">
<!--
.style1 {font-size: 12px}
-->
</style></head>
<body>
<p>
<table width="186" height="39" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>姓名</td>
<td>密码</td>
</tr>
<%
set rs=server.createobject("adodb.recordset")
conn = "dbq=" + server.mappath("zheng.mdb") + ";defaultdir=;driver={microsoft access driver (*.mdb)};"
sql="select * from user"
rs.open sql,conn,1,2
rs.pagesize=6 '设置页面显示得页数
if request("page")<>"" then
epage=cint(request("page"))
if epage<1 then epage=1
if epage>rs.pagecount then epage=rs.pagecount
else
epage=1
end if
rs.absolutepage=epage
for i=0 to rs.pagesize-1
if rs.bof or rs.eof then exit for
%><tr>
<td><%=rs("name")%></td>
<td><%=rs("pass")%></td>
</tr>
<%
rs.movenext
next
%>
</table>
<div align="left"><span class="style1">
<form method="get" onsubmit=""document.location ="c.asp?page='+ this.page.value;return false;'">
<%if epage=1 then response.write("首页")else response.write("<a href='c.asp?page=1'>"&"首页"&"</a>")%>
<%if epage=1 then response.write("上一页")else response.write"<a href=c.asp?page="&epage-1&">上一页</a>"%>
<%if epage = rs.pagecount then response.write("下一页")else response.write"<a href=c.asp?page="&epage+1&">下一页</a>"%>
<%if epage = rs.pagecount then response.write("末页")else response.write"<a href=c.asp?page="&rs.pagecount&">末页</a>"%>
现在是第<font color="red"><%=epage%></font>页一共有<font color="red"><%=rs.pagecount%></font>页
<input name="page" value="<%=epage%>" maxlength=5 tyep=text />
页
<input type=submit value=go style="font-size:12px;border:1px solid #cccccc;width:23px;" /></form>
</div>
<p> </p>
<p>
<%
name=request("name")
pass=request("pass")
if name<>"" and pass<>"" then
rs.addnew
rs("name")=name
rs("pass")=pass
rs.update
rs.close
end if
%>
</p>
</p>
<form id="form1" name="form1" method="post" action="">
<p>
<input name="name" type="text" id="name" />
</p>
<p>
<input name="pass" type="text" id="pass" />
<input type="submit" name="submit" value="提交" />
</p>
</form>
<p>
<table width="63%" border="0" cellpadding="0" cellspacing="1" bgcolor="#0000ff" style="border-collapse: collapse">
<%
set mrs=server.createobject("adodb.recordset")
conn = "dbq=" + server.mappath("zheng.mdb") + ";defaultdir=;driver={microsoft access driver (*.mdb)};"
sql="select * from user"
mrs.open sql,conn,1,1
if mrs.bof and mrs.eof then
response.write"<span>没有任何记录</span>"
response.end
else
mrs.pagesize =6'每页记录条数
icount=mrs.recordcount '记录总数
ipagesize=mrs.pagesize
maxpage=mrs.pagecount
page=request("page")
if not isnumeric(page) or page="" then
page=1
else
page=cint(page)
end if
if page<1 then
page=1
elseif page>maxpage then
page=maxpage
end if
mrs.absolutepage=page
if page=maxpage then
x=icount-(maxpage-1)*ipagesize
else
x=ipagesize
end if
end if
for i=1 to mrs.pagesize
%>
<tr>
<td width="64%" bgcolor="#ffffff" class="style1"><%=mrs("name")%></td>
<td width="36%" bgcolor="#ffffff" class="style1"><%=mrs("pass")%></td>
</tr><%
mrs.movenext
if mrs.eof then exit for
next
mrs.close
set mrs=nothing
%>
<tr>
<td colspan="2" bgcolor="#cccccc">
<span class="style1">
<%
call pagecontrol(icount,maxpage,page)
sub pagecontrol(icount,pagecount,page)
'生成上一页下一页链接
dim query, a, x, temp
action = "http://" & request.servervariables("http_host") & request.servervariables("script_name")
query = split(request.servervariables("query_string"), "&")
for each x in query
a = split(x, "=")
if strcomp(a(0), "page", vbtextcompare) <> 0 then
temp = temp & a(0) & "=" & a(1) & "&"
end if
next
response.write("<table border='0' cellpadding='3' style='border-collapse: collapse' width='100%' align='center'>")
response.write("<form method=get onsubmit=""document.location = '" & action & "?" & temp & "page='+ this.page.value;return false;""><tr>")
response.write("<td align='center' bgcolor='#ffffff'>")
if page<=1 then
response.write ("首页 " )
response.write ("上一页 ")
else
response.write("<a href=" & action & "?" & temp & "page=1>首页</a> ")
response.write("<a href=" & action & "?" & temp & "page=" & (page-1) & ">上一页</a> ")
end if
if page>=pagecount then
response.write ("下一页 ")
response.write ("尾页 ")
else
response.write("<a href=" & action & "?" & temp & "page=" & (page+1) & ">下一页</a> ")
response.write("<a href=" & action & "?" & temp & "page=" & pagecount & ">尾页</a> ")
end if
response.write(" 页次:" & page & "/" & pagecount & " 页")
response.write(" 共有 " & icount & " 条留言")
response.write(" 转到 " & "<input tyep=text name=page maxlength=5 value=" & page & " style='font-size: 12px;border: 1px solid #cccccc;width:23px;'>" & " 页 <input type=submit style=""font-size: 9pt"" value=go style='font-size: 12px;border: 1px solid #cccccc;width:23px;'>")
response.write("</td></tr></form>")
response.write("</table>")
end sub
%>
</span></td>
</tr>
</table>
<span class="style1">
</p>
</form>
</body>
</html>
上一篇: 对URL地址进行编码 优化2
下一篇: ASP变量加变量实现代码