ASP分页显示代码问题-第一页能正常显示,后面点击按钮没反应。。。急~
详细代码如下,拜托~~~~~我是新人,共只有15分,能出效果全给了!!!!<%@LANGUAGE="VBSCRIPT"CODEPAGE="936"%><!--#inclu...
详细代码如下,拜托~~~~~我是新人,共只有15分,能出效果全给了!!!!
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="conn.asp"-->
<%
response.Expires=0 '使浏览器缓存的页面立即过期
const intpagesize=3
'intcur代表当前要显示的页数,inttotal代表总页面,i代表循环变量
dim intcur,inttotal,i
dim rs
if request.ServerVariables("content_length")=0 then
intcur=1
else
intcur=cint(request.form("curpage"))
select case request.form("page")
case"首页"
intcur=1
case"上一页"
intcur=intcur-1
case"下一页"
intcur=intcur+1
case"尾页"
intcur=cint(request.form("lastpage"))
end select
end if
set rs=server.CreateObject("adodb.recordset")
strsql="select * from book order by bookname"
rs.cursorlocation=3 'adUseClient
rs.cursortype=adOpenStatic
rs.cachesize=intpagesize
rs.open strsql,conn
if rs.recordcount=0 then
response.write"对不起,数据库中没有信息记录"
else
rs.pagesize=intpagesize
if not rs.eof then
rs.absolutepage=intcur '设置当前记录所在的页号
end if
inttotal=rs.pagecount '获得总页数
%>
<html>
<head>
<title>分页显示书籍记录</title>
</head>
<body>
<center>本店现有<%=rs.recordcount%>本图书,共<%=inttotal%>页,当前是第<%=intcur%>页</center>
<p>
<form method=post action="<%=request.ServerVariables("SCRIPT_NAME")%>">
<input name="curpage" type="hidden" id="curpbbbbage" value="<%=intcur%>">
<input name="lastpage" type="hidden" id="lastpage" value="<%=inttotal%>">
<input name="page" type="submit" id="page" value="首页">
<% '如果当前不是第一页则显示上一页按钮
if intcur>1 then
%>
<input name="page" type="button" value="上一页">
<%end if
'如果当前不是最后一页,显示下一页按钮
if intcur<>inttotal then
%>
<input name="page" type="button" value="下一页">
<%end if%>
<input name="page" type="button" value="尾页">
</form>
<%
'使用表格显示ACCESS数据库中book表中的内容
i=0
%>
<table border="1" width="500">
<tr>
<td>编号</td>
<td>书名</td>
<td>作者</td>
<td>价格</td>
<td>类型</td>
</tr>
<% do while not rs.eof and i<rs.pagesize
%>
<tr>
<td><%=rs.absoluteposition%></td>
<td><%=rs("bookname")%></td>
<td><%=rs("writer")%></td>
<td><%=rs("price")%></td>
<td><%=rs("type")%></td>
</tr>
<%rs.movenext
i=i+1
loop
%>
</table>
<%rs.close
set rs=nothing
end if
%>
</body>
</html>
libmw~谢谢你的答案,但是我把代码放进去后测试浏览器提示“网页有错误”啊??缺少对象什么的。。。 展开
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="conn.asp"-->
<%
response.Expires=0 '使浏览器缓存的页面立即过期
const intpagesize=3
'intcur代表当前要显示的页数,inttotal代表总页面,i代表循环变量
dim intcur,inttotal,i
dim rs
if request.ServerVariables("content_length")=0 then
intcur=1
else
intcur=cint(request.form("curpage"))
select case request.form("page")
case"首页"
intcur=1
case"上一页"
intcur=intcur-1
case"下一页"
intcur=intcur+1
case"尾页"
intcur=cint(request.form("lastpage"))
end select
end if
set rs=server.CreateObject("adodb.recordset")
strsql="select * from book order by bookname"
rs.cursorlocation=3 'adUseClient
rs.cursortype=adOpenStatic
rs.cachesize=intpagesize
rs.open strsql,conn
if rs.recordcount=0 then
response.write"对不起,数据库中没有信息记录"
else
rs.pagesize=intpagesize
if not rs.eof then
rs.absolutepage=intcur '设置当前记录所在的页号
end if
inttotal=rs.pagecount '获得总页数
%>
<html>
<head>
<title>分页显示书籍记录</title>
</head>
<body>
<center>本店现有<%=rs.recordcount%>本图书,共<%=inttotal%>页,当前是第<%=intcur%>页</center>
<p>
<form method=post action="<%=request.ServerVariables("SCRIPT_NAME")%>">
<input name="curpage" type="hidden" id="curpbbbbage" value="<%=intcur%>">
<input name="lastpage" type="hidden" id="lastpage" value="<%=inttotal%>">
<input name="page" type="submit" id="page" value="首页">
<% '如果当前不是第一页则显示上一页按钮
if intcur>1 then
%>
<input name="page" type="button" value="上一页">
<%end if
'如果当前不是最后一页,显示下一页按钮
if intcur<>inttotal then
%>
<input name="page" type="button" value="下一页">
<%end if%>
<input name="page" type="button" value="尾页">
</form>
<%
'使用表格显示ACCESS数据库中book表中的内容
i=0
%>
<table border="1" width="500">
<tr>
<td>编号</td>
<td>书名</td>
<td>作者</td>
<td>价格</td>
<td>类型</td>
</tr>
<% do while not rs.eof and i<rs.pagesize
%>
<tr>
<td><%=rs.absoluteposition%></td>
<td><%=rs("bookname")%></td>
<td><%=rs("writer")%></td>
<td><%=rs("price")%></td>
<td><%=rs("type")%></td>
</tr>
<%rs.movenext
i=i+1
loop
%>
</table>
<%rs.close
set rs=nothing
end if
%>
</body>
</html>
libmw~谢谢你的答案,但是我把代码放进去后测试浏览器提示“网页有错误”啊??缺少对象什么的。。。 展开
展开全部
有你这么翻页的? 我只有给你加个JS来实现:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="conn.asp"-->
<%
response.Expires=0 '使浏览器缓存的页面立即过期
const intpagesize=3
'intcur代表当前要显示的页数,inttotal代表总页面,i代表循环变量
dim intcur,inttotal,i
dim rs
if request.ServerVariables("content_length")=0 then
intcur=1
else
intcur=cint(request.form("curpage"))
select case request.form("page")
case"首页"
intcur=1
case"上一页"
intcur=intcur-1
case"下一页"
intcur=intcur+1
case"尾页"
intcur=cint(request.form("lastpage"))
end select
end if
set rs=server.CreateObject("adodb.recordset")
strsql="select * from book order by bookname"
rs.cursorlocation=3 'adUseClient
rs.cursortype=adOpenStatic
rs.cachesize=intpagesize
rs.open strsql,conn
if rs.recordcount=0 then
response.write"对不起,数据库中没有信息记录"
else
rs.pagesize=intpagesize
if not rs.eof then
rs.absolutepage=intcur '设置当前记录所在的页号
end if
inttotal=rs.pagecount '获得总页数
%>
<html>
<head>
<title>分页显示书籍记录</title>
</head>
<script type="text/javascript">
function submitForm(obj){
var form=document.getElementById("form1");
form.page.value=obj.value;
form.submit();
}
</script>
<body>
<center>本店现有<%=rs.recordcount%>本图书,共<%=inttotal%>页,当前是第<%=intcur%>页</center>
<p>
<form method=post action="<%=request.ServerVariables("SCRIPT_NAME")%>">
<input name="curpage" type="hidden" id="curpbbbbage" value="<%=intcur%>">
<input name="lastpage" type="hidden" id="lastpage" value="<%=inttotal%>">
<input type="button" onClick="submitForm(this)" value="首页">
<% '如果当前不是第一页则显示上一页按钮
if intcur>1 then
%>
<input onClick="submitForm(this)" type="button" value="上一页">
<%end if
'如果当前不是最后一页,显示下一页按钮
if intcur<>inttotal then
%>
<input onClick="submitForm(this)" type="button" value="下一页">
<%end if%>
<input onClick="submitForm(this)" type="button" value="尾页">
</form>
<%
'使用表格显示ACCESS数据库中book表中的内容
i=0
%>
<table border="1" width="500">
<tr>
<td>编号</td>
<td>书名</td>
<td>作者</td>
<td>价格</td>
<td>类型</td>
</tr>
<% do while not rs.eof and i<rs.pagesize
%>
<tr>
<td><%=rs.absoluteposition%></td>
<td><%=rs("bookname")%></td>
<td><%=rs("writer")%></td>
<td><%=rs("price")%></td>
<td><%=rs("type")%></td>
</tr>
<%rs.movenext
i=i+1
loop
%>
</table>
<%rs.close
set rs=nothing
end if
%>
</body>
</html>
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="conn.asp"-->
<%
response.Expires=0 '使浏览器缓存的页面立即过期
const intpagesize=3
'intcur代表当前要显示的页数,inttotal代表总页面,i代表循环变量
dim intcur,inttotal,i
dim rs
if request.ServerVariables("content_length")=0 then
intcur=1
else
intcur=cint(request.form("curpage"))
select case request.form("page")
case"首页"
intcur=1
case"上一页"
intcur=intcur-1
case"下一页"
intcur=intcur+1
case"尾页"
intcur=cint(request.form("lastpage"))
end select
end if
set rs=server.CreateObject("adodb.recordset")
strsql="select * from book order by bookname"
rs.cursorlocation=3 'adUseClient
rs.cursortype=adOpenStatic
rs.cachesize=intpagesize
rs.open strsql,conn
if rs.recordcount=0 then
response.write"对不起,数据库中没有信息记录"
else
rs.pagesize=intpagesize
if not rs.eof then
rs.absolutepage=intcur '设置当前记录所在的页号
end if
inttotal=rs.pagecount '获得总页数
%>
<html>
<head>
<title>分页显示书籍记录</title>
</head>
<script type="text/javascript">
function submitForm(obj){
var form=document.getElementById("form1");
form.page.value=obj.value;
form.submit();
}
</script>
<body>
<center>本店现有<%=rs.recordcount%>本图书,共<%=inttotal%>页,当前是第<%=intcur%>页</center>
<p>
<form method=post action="<%=request.ServerVariables("SCRIPT_NAME")%>">
<input name="curpage" type="hidden" id="curpbbbbage" value="<%=intcur%>">
<input name="lastpage" type="hidden" id="lastpage" value="<%=inttotal%>">
<input type="button" onClick="submitForm(this)" value="首页">
<% '如果当前不是第一页则显示上一页按钮
if intcur>1 then
%>
<input onClick="submitForm(this)" type="button" value="上一页">
<%end if
'如果当前不是最后一页,显示下一页按钮
if intcur<>inttotal then
%>
<input onClick="submitForm(this)" type="button" value="下一页">
<%end if%>
<input onClick="submitForm(this)" type="button" value="尾页">
</form>
<%
'使用表格显示ACCESS数据库中book表中的内容
i=0
%>
<table border="1" width="500">
<tr>
<td>编号</td>
<td>书名</td>
<td>作者</td>
<td>价格</td>
<td>类型</td>
</tr>
<% do while not rs.eof and i<rs.pagesize
%>
<tr>
<td><%=rs.absoluteposition%></td>
<td><%=rs("bookname")%></td>
<td><%=rs("writer")%></td>
<td><%=rs("price")%></td>
<td><%=rs("type")%></td>
</tr>
<%rs.movenext
i=i+1
loop
%>
</table>
<%rs.close
set rs=nothing
end if
%>
</body>
</html>
展开全部
文件display.asp的代码如下:自己看代码用SQL建立一个数据库名为:student ,表名为: table ,字段随便设置
<%@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>无标题文档</title>
<style type="text/css">
<!--
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: none;
}
-->
</style></head>
<body>
<%
set conn = server.createobject("adodb.connection")
conn.open "Provider=SQLOLEDB.1;user ID=sa;Password=;Initial Catalog=student;Data Source=(local)"
set rs = createobject("adodb.recordset")
sql = ("select * from table")
rs.open sql,conn,1,1,adcmdtext
rs.pagesize = 3
page = clng(request("text1"))
if page < 1 then page = 1
if page > rs.pagecount then page = rs.pagecount
for k = 0 to rs.fields.count - 1
response.write rs.fields(k).name & " "
next
response.write "<br>"
rs.absolutepage = page
for ipage = 1 to rs.pagesize
recno = (page - 1) * rs.pagesize + ipage
response.write recno
for k = 0 to rs.fields.count - 1
response.write rs.fields(k).value & " "
next
response.write "<br>"
rs.movenext
if rs.eof then exit for
next
%>
<form action="display.asp" method="get">
<% if page <> 1 then
response.write "<A href=display.asp?text1=1>第一页</A> "
response.write "<a href=display.asp?text1=" & (page-1) & ">上一页</a> "
end if
if page <> rs.pagecount then
response.write "<A href=display.asp?text1=" & (page+1) & ">下一页</a> "
response.write "<a href=display.asp?text1=" & rs.pagecount & ">最后一页</a>"
end if
%>
<p>输入页数: <input type="text" name="text1" size="3"> <input type="submit" value="提交"> 页数: <% =page %>/<% =rs.pagecount %></p>
</form>
</body>
</html>
<%@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>无标题文档</title>
<style type="text/css">
<!--
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: none;
}
-->
</style></head>
<body>
<%
set conn = server.createobject("adodb.connection")
conn.open "Provider=SQLOLEDB.1;user ID=sa;Password=;Initial Catalog=student;Data Source=(local)"
set rs = createobject("adodb.recordset")
sql = ("select * from table")
rs.open sql,conn,1,1,adcmdtext
rs.pagesize = 3
page = clng(request("text1"))
if page < 1 then page = 1
if page > rs.pagecount then page = rs.pagecount
for k = 0 to rs.fields.count - 1
response.write rs.fields(k).name & " "
next
response.write "<br>"
rs.absolutepage = page
for ipage = 1 to rs.pagesize
recno = (page - 1) * rs.pagesize + ipage
response.write recno
for k = 0 to rs.fields.count - 1
response.write rs.fields(k).value & " "
next
response.write "<br>"
rs.movenext
if rs.eof then exit for
next
%>
<form action="display.asp" method="get">
<% if page <> 1 then
response.write "<A href=display.asp?text1=1>第一页</A> "
response.write "<a href=display.asp?text1=" & (page-1) & ">上一页</a> "
end if
if page <> rs.pagecount then
response.write "<A href=display.asp?text1=" & (page+1) & ">下一页</a> "
response.write "<a href=display.asp?text1=" & rs.pagecount & ">最后一页</a>"
end if
%>
<p>输入页数: <input type="text" name="text1" size="3"> <input type="submit" value="提交"> 页数: <% =page %>/<% =rs.pagecount %></p>
</form>
</body>
</html>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询