asp分页问题

afei2003 2004-06-10 08:29:45
小弟有一分页问题.代码如下
<%@ Language=VBScript %>
<!--#include file="conn_access.asp"-->
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<table width="100%" height="216" border="0" cellpadding="0" cellspacing="0">
<tr>
<form action=test.asp method="post" name="search" onsubmit="return FormSubmit()">
<td>
<table width="97%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="34%" height="20" align="right" valign="bottom"><IMG height=20 src="IMAGES/asd.gif" width=103></td>
<td width="31%">   型号:
<input name="cpxh" size="14" maxlength="50" value=""></td>
<td width="14%"><INPUT type=submit value=查询 name=submit_afei>
</td>
<td width="15%">
</td>
<td width="6%"></td>
</tr>
</table></td>
</form>
</tr>
<tr>
<td height="287" align="center" valign="top">

<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr >
<td align="center" width="20%" height="20"><font color="#339933">型号:</font></td>
<td align="center" width="20%" height="20"><font color="#339933">厂牌:</font></td>
<td align="center" width="20%" height="20"><font color="#339933">数量:</font></td>
<td align="center" width="20%" height="20"><font color="#339933">批号:</font></td>
<td align="center" width="20%" height="20"><font color="#339933">价格:</font></td>
</tr>
<%
'xh = "AMP"
xh = Request.Form("cpxh")
'Response.Write(xh)
set rs=Server.CreateObject("ADODB.Recordset")
Set rs.ActiveConnection=conn
rs.CursorType=3
rs.Open "select * from cpxh where cpxh like '%" & xh & "%'"
rs.PageSize=20
page=Clng(Request.QueryString("page"))
if page<1 then
page=1
end if
if page>rs.PageCount then
page=rs.PageCount
end if
rs.AbsolutePage=page
for i=1 to rs.PageSize
varNo =(page-1)*rs.PageSize+i
%>
<tr bgcolor=#EAF4FE >
<td align="center" width="20%" height="20"><%=rs.Fields("cpxh").Value%></td>
<td align="center" width="20%" height="20"> </td>
<td align="center" width="20%" height="20"><%=rs.Fields("cpcount").Value%></td>
<td align="center" width="20%" height="20"> </td>
<td align="center" width="80%" height="20"> </td>
</tr>
<%
rs.MoveNext
if rs.EOF then exit for
next
%>
<tr>
<td colspan=5 align="center" height="20">
<%
Response.Write(rs.PageCount)
if page=1 then
Response.Write("第一页")
else
Response.Write("<a href=test.asp?page=1>[第一页]</a>")
end if
if page=1 then
Response.Write("上一页")
else
Response.Write("<a href=test.asp?page="&page-1& ">[上一页]</a>")
end if
if page=rs.PageCount then
Response.Write("下一页")
else
Response.Write("<a href=test.asp?page="&page+1&">[下一页]</a>")
end if
if page =rs.PageCount then
Response.Write("最后一页")
else
Response.Write("<a href=test.asp?page="&rs.PageCount&">[最后一页]</a>")
end if
conn.Close
if conn.State =0 then
end if
set conn=nothing
%>
</td></tr><table></BODY></HTML>
问题是,第一页能够按照查找的关键字显示的,但是第二页以后就不能 正常显示。他显示的是数据库里面全部的记录。
恳请解答一二!
...全文
152 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
nchen123 2004-06-11
  • 打赏
  • 举报
回复
你搜索“存储过程分页” 能找到一堆, 我就不罗嗦了。
afei2003 2004-06-11
  • 打赏
  • 举报
回复
我的问题解决了,谢谢各位。尤其是lawdoor 和 wanghr100
现在我把修改过代码传上来。供大家参考:
<%@ Language=VBScript %>
<!--#include file="conn.asp"-->
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<table width="100%" height="216" border="0" cellpadding="0" cellspacing="0">
<tr>
<form action=test.asp method="post" name="search" onsubmit="return FormSubmit()">
<td>
<table width="97%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="34%" height="20" align="right" valign="bottom"><IMG height=20 src="IMAGES/asd.gif" width=103></td>
<td width="31%">   型号:
<input name="cpxh" size="14" maxlength="50" value=""></td>
<td width="14%"><INPUT type=submit value=查询 name=submit_afei>
</td>
<td width="15%">
</td>
<td width="6%"></td>
</tr>
</table></td>
</form>
</tr>
<tr>
<td height="287" align="center" valign="top">

<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr >
<td align="center" width="20%" height="20"><font color="#339933">型号:</font></td>
<td align="center" width="20%" height="20"><font color="#339933">厂牌:</font></td>
<td align="center" width="20%" height="20"><font color="#339933">数量:</font></td>
<td align="center" width="20%" height="20"><font color="#339933">批号:</font></td>
<td align="center" width="20%" height="20"><font color="#339933">价格:</font></td>
</tr>
<%
xh = Request("cpxh")
set rs=Server.CreateObject("ADODB.Recordset")
Set rs.ActiveConnection=conn
rs.CursorType=3
rs.Open "select * from cpxh where cpxh like '%" & xh & "%'"
rs.PageSize=20
page=Clng(Request.QueryString("page"))
if page<1 then
page=1
end if
if page>rs.PageCount then
page=rs.PageCount
end if
rs.AbsolutePage=page
%>
<br>当前页码:<%=page%>/<%=rs.PageCount%>
<%
for i=1 to rs.PageSize
varNo =(page-1)*rs.PageSize+i
%>
<tr bgcolor=#EAF4FE >
<td align="center" width="20%" height="20"><%=rs.Fields("cpxh").Value%></td>
<td align="center" width="20%" height="20"> </td>
<td align="center" width="20%" height="20"><%=rs.Fields("cpcount").Value%></td>
<td align="center" width="20%" height="20"> </td>
<td align="center" width="80%" height="20"> </td>
</tr>
<%
rs.MoveNext
if rs.EOF then exit for
next
%>
<tr>
<td colspan=5 align="center" height="20">
<%
if page=1 then
Response.Write("第一页")
else
Response.Write("<a href=test.asp?page=1&cpxh="&xh&">[第一页]</a>")
end if
if page=1 then
Response.Write("上一页")
else
Response.Write("<a href=test.asp?page="&page-1&"&cpxh="&xh&">[上一页]</a>")
end if
if page=rs.PageCount then
Response.Write("下一页")
else
Response.Write("<a href=test.asp?page="&page+1&"&cpxh="&xh&">[下一页]</a>")
end if
if page =rs.PageCount then
Response.Write("最后一页")
else
Response.Write("<a href=test.asp?page="&rs.PageCount&"&cpxh="&xh&">[最后一页]</a>")
end if%>
<select name="sel_page" onchange="javascript:location=this.options[this.selectedIndex].value;">
<%
for i = 1 to rs.PageCount
if i = intpage then%>
<option value="test.asp?page=<%=i%>&cpxh=<%=Request("cpxh")%>" selected><%=i%></option>
<%else%>
<option value="test.asp?page=<%=i%>&cpxh=<%=Request("cpxh")%>"><%=i%></option>
<%
end if
next
%>
</select><font >页</font>
<%
conn.Close
if conn.State =0 then
end if
set conn=nothing
%>
</td></tr></table>
</BODY>
</HTML>
Miriamy 2004-06-10
  • 打赏
  • 举报
回复
to inelm(木野狐)
用存储过程怎么写呀,

能请教一下吗》
给一点提示好吗?》
wanghr100 2004-06-10
  • 打赏
  • 举报
回复
问题一:

xh = Request.Form("cpxh")
->
xh = Request("cpxh")

'因为,第一次查询时是method=post
'如果要用要URL后接查询字符串的话,得用Request.QueryString("cpxh")来接收.
'Request("cpxh")可以接收到post,get.

问题二:

翻页时将cpxh参数也带上:
<a href="test.asp?page=<%=rs.PageCount%>&cpxh=<%=request("cpxh")%>">
hellospring 2004-06-10
  • 打赏
  • 举报
回复
asp直接能实现吗 不想用组件
nchen123 2004-06-10
  • 打赏
  • 举报
回复
在 asp 程序中取出全部记录然后分页的做法很低效, 可以考虑使用存储过程只获取指定页的数据, 或者用组件封装数据库的存取。 这样 asp 页面只负责显示页码和跳转而已,非常简单。 我最近参与做的一个查询系统就是这么做的, 使用 delphi 编写的组件来得到指定页的数据。
afei2003 2004-06-10
  • 打赏
  • 举报
回复
lawdoor:
我照你的作了,但是不行,
郁闷
不过我您的回复之速度如此之快,
真是高兴!
谢谢◎!
我先到书上再找找!
lawdoor 2004-06-10
  • 打赏
  • 举报
回复
你的分页有问题,这样吧,我给你一个分页代码套进去程序,看看怎么样?
<!-- #include file="../Inc/conn.asp" -->
<%
dim i,intPage,page,pre,last,filepath
set rs = server.CreateObject("adodb.recordset")
sql="select * from user order by user_ID desc"
rs.PageSize = 20 '这里设定每页显示的记录数
rs.CursorLocation = 3
rs.Open sql,conn,0,2,1 '这里执行你查询SQL并获得结果记录集
pre = true
last = true
page = trim(Request.QueryString("page"))

if len(page) = 0 then
intpage = 1
pre = false
else
if cint(page) =< 1 then
intpage = 1
pre = false
else
if cint(page) >= rs.PageCount then
intpage = rs.PageCount
last = false
else
intpage = cint(page)
end if
end if
end if
if not rs.eof then
rs.AbsolutePage = intpage
end if
%>
循环体开始:
<%
for i=1 to rs.PageSize
if rs.EOF or rs.BOF then exit for
%>
..................
..................
...................
<%
rs.movenext
next
%>
循环体结束
分页部分:
<table width="99%" border="1" cellpadding="2" cellspacing="2" borderColorLight=#808080 borderColorDark=#ffffff>
<tr>
<%if rs.pagecount > 0 then%>
<td width="13%" align="left">当前页<%=intpage%>/<%=rs.PageCount%></td>
<%else%>
<td width="41%" align="left">当前页0/0</td><%end if%>
<td width="46%" align="right"> <a href="document_manage.asp?page=1">首页</a>|
<%if pre then%>
<a href="document_manage.asp?page=<%=intpage -1%>">上页</a>| <%end if%>
<%if last then%>
<a href="document_manage.asp?page=<%=intpage +1%>">下页</a> |<%end if%>
<a href="document_manage.asp?page=<%=rs.PageCount%>">尾页</a>|转到第
<select name="sel_page" onchange="javascript:location=this.options[this.selectedIndex].value;">
<%
for i = 1 to rs.PageCount
if i = intpage then%>
<option value="document_manage.asp?page=<%=i%>" selected><%=i%></option>
<%else%>
<option value="document_manage.asp?page=<%=i%>"><%=i%></option>
<%
end if
next
%>
</select>页</font>
</td>
</tr>
</table>
分页是下拉显示的,很好用!将你的参数带上看看有什么变化没有???
afei2003 2004-06-10
  • 打赏
  • 举报
回复
lawdoor
comflyer0590
我怎么还是不行呢?

他还是要把全部的都读出来才高兴
comflyer0590 2004-06-10
  • 打赏
  • 举报
回复
顶一个 对的 如果还有其他条件也逐个增加参数带上,再把它填入到sql语句里就行了。
lawdoor 2004-06-10
  • 打赏
  • 举报
回复
翻页时将cpxh参数也带上:
<a href="test.asp?page=<%=rs.PageCount%>&cpxh=<%=request("cpxh")%>">

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧