ASP查询后分页显示问题!急救!
我做了个查询页面当我输入条件后,进入显示页面后第一页可以显示符合要求的记录,但当我点击下一页后,显示的记录就不在是我所要查询的记录了!问题是分页查询的参数没有带到下一页去?但是我又不会处理!请各位老兄帮帮忙解决!
原码如下:
<!--#include file= "../Conndb.asp "-->
<html>
<head>
<title> 货品库存查询--按客户货号 </title>
<%
CustCode = Trim(Request.Form( "CustCode "))
Session( "CustCode ") = CustCode
Session( "CurrentFields ") = "DES2 "
Set rs = Server.CreateObject( "ADODB.RecordSet ")
<!-- 读取数据到记录集rs中 -->
sql = "SELECT ITEM_CODE As 货品编号, DES As 货品名称, DES2 As 客户货号 " _
+ "FROM UN_ITEM1 WHERE DES2 Like ' " & CustCode & "% ' "
rs.Open sql,conn,1,1
<!-- 在表格中显示项目信息 -->
Rs.Pagesize=15
Page=CLng(Request.QueryString( "Page "))
if Page <1 then
Page=1
end if
if Page> Rs.PageCount then
Page=Rs.PageCount
end if
%>
</head>
<body link= "#000080 " vlink= "#080080 ">
<form name= "ItemForm " method= "POST " action= "ItemListBySecondName.asp ">
<p align= "center "> <font color= "#000080 "> <b> <font style= "font-size: 12pt "> 货 品 </font> <font color= "#000080 "> <b> <font style= "font-size: 12pt "> 库 存 </font> </b> </font> <font style= "font-size: 12pt "> 查 询( <%=Session( "SelectDataBase ")%> ) </font> </b> </font> </p>
<p align= "left "> <font color= "#000080 "> 按客户货号:
<input name= "CustCode " type= "text " id= "CustCode ">
<input name= "cmdQuery " type= "submit " id= "cmdQuery " value= "查询 ">
</font> <span class= "style1 "> %表示任意符号 _表示一个符号 </span> </p>
<font color= "000080 "> 当前页码: <%=Page%> / <%=Rs.PageCount%> </font>
<table align= "center " border= "1 " cellspacing= "0 " width= "100% " bordercolorlight= "#000080 " bordercolordark= "#FFFFFF ">
<tr>
<td width= "15% " align= "center " bgcolor= "#C1E0FF "> <strong> 货品编号 </strong> </td>
<td width= "25% " align= "center " bgcolor= "#C1E0FF "> <strong> 客户名称 </strong> </td>
<td width= "25% " align= "center " bgcolor= "#C1E0FF "> <strong> 货品名称 </strong> </td>
<td width= "25% " align= "center " bgcolor= "#C1E0FF "> <strong> 客户货号 </strong> </td>
</tr>
<%
if rs.eof then
Response.Write " <tr> <td colspan=10 align=center> <font style= 'COLOR:Red '> 没有您想要查询的信息。 </font> </td> </tr> </table> "
else
Rs.absolutePage=Page
for i=1 to Rs.Pagesize
varNo=(Page-1)*Rs.Pagesize+i
kfcode = Mid(rs( "货品编号 "),4,3)
Set CodeRs = Server.CreateObject( "ADODB.RecordSet ")
sql = "SELECT custcode FROM kfcode WHERE kfcode = ' " & kfcode & " ' "
CodeRs.Open sql,conn,1,1
Response.Write " <tr> "
Response.Write " <td align= 'left '> " & rs( "货品编号 ") & " </td> "
if CodeRs.eof then
Response.Write " <td align= 'center '> </td> "
CodeRs.Close
else
custcode = CodeRs( "custcode ")
CodeRs.Close
Set CodeRs = Server.CreateObject( "ADODB.RecordSet ")
sql = "SELECT NAME_C AS 客户名称 FROM ARCODAT1 WHERE ACCOU_NO = ' " & custcode & " ' "
CodeRs.Open sql,conn,1,1
if CodeRs.eof then
Response.Write " <td align= 'center '> </td> "
else
Response.Write " <td align= 'center '> " & CodeRs( "客户名称 ") & " </td> "
end if
end if
Response.Write " <td align= 'center '> " & rs( "货品名称 ") & " </td> "
Response.Write " <td align= 'center '> " & rs( "客户货号 ") & " </td> "
Response.Write " </tr> "
rs.movenext
if Rs.eof then exit for
next
end if
%>
</table>
<br>
<%
if Page=1 then
Response.Write( "第一页 ")
else
Response.Write( " <a href=ItemListBySecondName.asp?Page=1> 第一页 </a> ")
end if
if Page=1 then
Response.Write( "上一页 ")
else
Response.Write( " <a href=ItemListBySecondName.asp?Page= "&Page-1& "> 上一页 </a> ")
end if
if Page=Rs.PageCount then
Response.Write( "下一页 ")
else
Response.Write( " <a href=ItemListBySecondName.asp?Page= "&Page+1& "> 下一页 </a> ")
end if
if Page=Rs.PageCount then
Response.Write( "最后一页 ")
else
Response.Write( " <a href=ItemListBySecondName.asp?Page= "&Rs.PageCount& "> 最后一页 </a> ")
end if
%>
</form>
</body>
</html>
[解决办法]
这句
CustCode = Trim(Request.Form( "CustCode "))
改成
CustCode = Trim(Request( "CustCode "))
然后把你代码和下面相同的这一块代码换成下面的。
<%
if Page=1 then
Response.Write( "第一页 ")
else
Response.Write( " <a href=ItemListBySecondName.asp?Page=1&CustCode= "&CustCode& "> 第一页 </a> ")
end if
if Page=1 then
Response.Write( "上一页 ")
else
Response.Write( " <a href=ItemListBySecondName.asp?Page= "&Page-1& "&CustCode= "&CustCode& "> 上一页 </a> ")
end if
if Page=Rs.PageCount then
Response.Write( "下一页 ")
else
Response.Write( " <a href=ItemListBySecondName.asp?Page= "&Page+1& "&CustCode= "&CustCode& "> 下一页 </a> ")
end if
if Page=Rs.PageCount then
Response.Write( "最后一页 ")
else
Response.Write( " <a href=ItemListBySecondName.asp?Page= "&Rs.PageCount& "&CustCode= "&CustCode& "> 最后一页 </a> ")
end if
%>
[解决办法]
代码我帮你修改了一下,看看是否符合你的要求:
<!--#include file= "../Conndb.asp "-->
<html>
<head>
<title> 货品库存查询--按客户货号 </title>
<%
CustCode = Trim(Request.Form( "CustCode "))
Session( "CustCode ") = CustCode
Session( "CurrentFields ") = "DES2 "
Set rs = Server.CreateObject( "ADODB.RecordSet ")
<!-- 读取数据到记录集rs中 -->
sql = "SELECT ITEM_CODE As 货品编号, DES As 货品名称, DES2 As 客户货号 " _
+ "FROM UN_ITEM1 WHERE DES2 Like ' " & CustCode & "% ' "
rs.Open sql,conn,1,1
<!-- 在表格中显示项目信息 -->
Rs.Pagesize=15
Page=CLng(Request.QueryString( "Page "))
if Page <1 then
Page=1
end if
if Page> Rs.PageCount then
Page=Rs.PageCount
end if
%>
</head>
<body link= "#000080 " vlink= "#080080 ">
<form name= "ItemForm " method= "POST " action= "ItemListBySecondName.asp ">
<p align= "center "> <font color= "#000080 "> <b> <font style= "font-size: 12pt "> 货 品 </font> <font color= "#000080 "> <b> <font style= "font-size: 12pt "> 库 存 </font> </b> </font> <font style= "font-size: 12pt "> 查 询( <%=Session( "SelectDataBase ")%> ) </font> </b> </font> </p>
<p align= "left "> <font color= "#000080 "> 按客户货号:
<input name= "CustCode " type= "text " id= "CustCode " value= " <%=CustCode%> ">
<input name= "cmdQuery " type= "submit " id= "cmdQuery " value= "查询 ">
</font> <span class= "style1 "> %表示任意符号 _表示一个符号 </span> </p>
<font color= "000080 "> 当前页码: <%=Page%> / <%=Rs.PageCount%> </font>
<table align= "center " border= "1 " cellspacing= "0 " width= "100% " bordercolorlight= "#000080 " bordercolordark= "#FFFFFF ">
<tr>
<td width= "15% " align= "center " bgcolor= "#C1E0FF "> <strong> 货品编号 </strong> </td>
<td width= "25% " align= "center " bgcolor= "#C1E0FF "> <strong> 客户名称 </strong> </td>
<td width= "25% " align= "center " bgcolor= "#C1E0FF "> <strong> 货品名称 </strong> </td>
<td width= "25% " align= "center " bgcolor= "#C1E0FF "> <strong> 客户货号 </strong> </td>
</tr>
<%
if rs.eof then
Response.Write " <tr> <td colspan=10 align=center> <font style= 'COLOR:Red '> 没有您想要查询的信息。 </font> </td> </tr> </table> "
else
Rs.absolutePage=Page
for i=1 to Rs.Pagesize
varNo=(Page-1)*Rs.Pagesize+i
kfcode = Mid(rs( "货品编号 "),4,3)
Set CodeRs = Server.CreateObject( "ADODB.RecordSet ")
sql = "SELECT custcode FROM kfcode WHERE kfcode = ' " & kfcode & " ' "
CodeRs.Open sql,conn,1,1
Response.Write " <tr> "
Response.Write " <td align= 'left '> " & rs( "货品编号 ") & " </td> "
if CodeRs.eof then
Response.Write " <td align= 'center '> </td> "
CodeRs.Close
else
custcode = CodeRs( "custcode ")
CodeRs.Close
Set CodeRs = Server.CreateObject( "ADODB.RecordSet ")
sql = "SELECT NAME_C AS 客户名称 FROM ARCODAT1 WHERE ACCOU_NO = ' " & custcode & " ' "
CodeRs.Open sql,conn,1,1
if CodeRs.eof then
Response.Write " <td align= 'center '> </td> "
else
Response.Write " <td align= 'center '> " & CodeRs( "客户名称 ") & " </td> "
end if
end if
Response.Write " <td align= 'center '> " & rs( "货品名称 ") & " </td> "
Response.Write " <td align= 'center '> " & rs( "客户货号 ") & " </td> "
Response.Write " </tr> "
rs.movenext
if Rs.eof then exit for
next
end if
%>
</table>
<br/>
<%
if Page=1 then
Response.Write( "第一页 ")
else
Response.Write( " <a href=ItemListBySecondName.asp?CustCode= "&CustCode& "&Page=1> 第一页 </a> ")
end if
if Page=1 then
Response.Write( "上一页 ")
else
Response.Write( " <a href=ItemListBySecondName.asp?CustCode= "&CustCode& "&Page= "&Page-1& "> 上一页 </a> ")
end if
if Page=Rs.PageCount then
Response.Write( "下一页 ")
else
Response.Write( " <a href=ItemListBySecondName.asp?CustCode= "&CustCode& "&Page= "&Page+1& "> 下一页 </a> ")
end if
if Page=Rs.PageCount then
Response.Write( "最后一页 ")
else
Response.Write( " <a href=ItemListBySecondName.asp?CustCode= "&CustCode& "&Page= "&Rs.PageCount& "> 最后一页 </a> ")
end if
%>
</form>
</body>
</html>
[解决办法]
上传你的文件到 http://www.access911.net/CSDN/,我帮你修改一下
[解决办法]
( " <a href=ItemListBySecondName.asp?Page= "&Rs.PageCount& "> 最后一页 </a> ")
我有办法啊,其实很简单的,如下:
:( " <a href=ItemListBySecondName.asp?Page= "&Rs.PageCount& "&Keyword= "&Keyword& "&> 最后一页 </a> ")
其中Keyword是你查询的关键字,这样让每一个连接都带有你的查询条件,就OK了。
[解决办法]
试试这个
<!--#include file= "../Conndb.asp "-->
<html>
<head>
<title> 货品库存查询--按客户货号 </title>
<%
if Trim(Request.Form( "CustCode ")) <> " " then
CustCode = Trim(Request.Form( "CustCode "))
Session( "CustCode ") = CustCode
Session( "CurrentFields ") = "DES2 "
else
CustCode=Trim(session( "CustCode "))
end if
Set rs = Server.CreateObject( "ADODB.RecordSet ")
<!-- 读取数据到记录集rs中 -->
sql = "SELECT ITEM_CODE As 货品编号, DES As 货品名称, DES2 As 客户货号 " _
+ "FROM UN_ITEM1 WHERE DES2 Like ' " & CustCode & "% ' "
rs.Open sql,conn,1,1
<!-- 在表格中显示项目信息 -->
Rs.Pagesize=15
Page=CLng(Request.QueryString( "Page "))
if Page <1 then
Page=1
end if
if Page> Rs.PageCount then
Page=Rs.PageCount
end if
%>
</head>
<body link= "#000080 " vlink= "#080080 ">
<form name= "ItemForm " method= "POST " action= "ItemListBySecondName.asp ">
<p align= "center "> <font color= "#000080 "> <b> <font style= "font-size: 12pt "> 货 品 </font> <font color= "#000080 "> <b> <font style= "font-size: 12pt "> 库 存 </font> </b> </font> <font style= "font-size: 12pt "> 查 询( <%=Session( "SelectDataBase ")%> ) </font> </b> </font> </p>
<p align= "left "> <font color= "#000080 "> 按客户货号:
<input name= "CustCode " type= "text " id= "CustCode ">
<input name= "cmdQuery " type= "submit " id= "cmdQuery " value= "查询 ">
</font> <span class= "style1 "> %表示任意符号 _表示一个符号 </span> </p>
<font color= "000080 "> 当前页码: <%=Page%> / <%=Rs.PageCount%> </font>
<table align= "center " border= "1 " cellspacing= "0 " width= "100% " bordercolorlight= "#000080 " bordercolordark= "#FFFFFF ">
<tr>
<td width= "15% " align= "center " bgcolor= "#C1E0FF "> <strong> 货品编号 </strong> </td>
<td width= "25% " align= "center " bgcolor= "#C1E0FF "> <strong> 客户名称 </strong> </td>
<td width= "25% " align= "center " bgcolor= "#C1E0FF "> <strong> 货品名称 </strong> </td>
<td width= "25% " align= "center " bgcolor= "#C1E0FF "> <strong> 客户货号 </strong> </td>
</tr>
<%
if rs.eof then
Response.Write " <tr> <td colspan=10 align=center> <font style= 'COLOR:Red '> 没有您想要查询的信息。 </font> </td> </tr> </table> "
else
Rs.absolutePage=Page
for i=1 to Rs.Pagesize
varNo=(Page-1)*Rs.Pagesize+i
kfcode = Mid(rs( "货品编号 "),4,3)
Set CodeRs = Server.CreateObject( "ADODB.RecordSet ")
sql = "SELECT custcode FROM kfcode WHERE kfcode = ' " & kfcode & " ' "
CodeRs.Open sql,conn,1,1
Response.Write " <tr> "
Response.Write " <td align= 'left '> " & rs( "货品编号 ") & " </td> "
if CodeRs.eof then
Response.Write " <td align= 'center '> </td> "
CodeRs.Close
else
custcode = CodeRs( "custcode ")
CodeRs.Close
Set CodeRs = Server.CreateObject( "ADODB.RecordSet ")
sql = "SELECT NAME_C AS 客户名称 FROM ARCODAT1 WHERE ACCOU_NO = ' " & custcode & " ' "
CodeRs.Open sql,conn,1,1
if CodeRs.eof then
Response.Write " <td align= 'center '> </td> "
else
Response.Write " <td align= 'center '> " & CodeRs( "客户名称 ") & " </td> "
end if
end if
Response.Write " <td align= 'center '> " & rs( "货品名称 ") & " </td> "
Response.Write " <td align= 'center '> " & rs( "客户货号 ") & " </td> "
Response.Write " </tr> "
rs.movenext
if Rs.eof then exit for
next
end if
%>
</table>
<br/>
<%
if Page=1 then
Response.Write( "第一页 ")
else
Response.Write( " <a href=ItemListBySecondName.asp?Page=1> 第一页 </a> ")
end if
if Page=1 then
Response.Write( "上一页 ")
else
Response.Write( " <a href=ItemListBySecondName.asp?Page= "&Page-1& "> 上一页 </a> ")
end if
if Page=Rs.PageCount then
Response.Write( "下一页 ")
else
Response.Write( " <a href=ItemListBySecondName.asp?Page= "&Page+1& "> 下一页 </a> ")
end if
if Page=Rs.PageCount then
Response.Write( "最后一页 ")
else
Response.Write( " <a href=ItemListBySecondName.asp?Page= "&Rs.PageCount& "> 最后一页 </a> ")
end if
%>
</form>
</body>
</html>