关于分页显示的问题。(100分)

  • 主题发起人 主题发起人 orchid_zlcn
  • 开始时间 开始时间
O

orchid_zlcn

Unregistered / Unconfirmed
GUEST, unregistred user!
各位高手,我的问题困扰了我好多天,请你们帮我看看程序。如果不按条件查询能正常显示多页数据。按条件查询数据库,第一页显示正常,但到下一页时就显示“对不起,数据库中没有相关信息!”(这句是判断RS.RecordCount为零的结果)。请问为什么?我该怎么做才能在实现按条件查询数据库多页显示。
<%@ Language=VBScript %>
<%
PgSz=20
Set Conn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.RecordSet")
department=request.form("department")
sql="SELECT *,ItemID.sItemName ,Department.sDepartmentName FROM PlanTable INNER JOIN Department ON PlanTable.sDepartmentID = Department.sDepartmentID INNER JOIN ItemID ON PlanTable.sItemID = ItemID.sItemID WHERE PlanTable.sDepartmentID= '"&amp;department&amp;"'"

Conn.open "xxxDSN","sa","xxxx"
RS.open sql,conn,1,1

If RS.RecordCount=0 then
response.write "<P><center>对不起,数据库中没有相关信息!</center></P>"
else
RS.PageSize = Cint(PgSz)
Total=RS.Pagecount
PageNo=Request("pageno")
if PageNo="" then
PageNo = 1
else
PageNo=PageNo+1
PageNo=PageNo-1
end if
ScrollAction = Request("ScrollAction")
if ScrollAction = "上一页" then
PageNo=PageNo-1
end if
if ScrollAction = "下一页" then
PageNo=PageNo+1
end if
if PageNo < 1 then

PageNo = 1
end if
n=1
RS.AbsolutePage = PageNo
Response.Write "<CENTER>"
position=RS.PageSize*PageNo
pagebegin
=position-RS.PageSize+1
if position < RS.RecordCount then
pagend=position
else

pagend= RS.RecordCount
end if
response.write "<center><h3><center><FONT color=darkmagenta size=5>需 求 计 划 公 共 信 息</FONT></CENTER></h3>"
Response.Write "<P><font color='Navy'><B>数据库查询结果:</B>"
Response.Write "(共有"&amp;RS.Pagecount&amp;"页," &amp;RS.RecordCount &amp;"条符合条件的信息,显示第"&amp;pagebegin
&amp;"条-第"&amp;pagend&amp;"条记录)</p>"

Response.Write "<TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0 BGCOLOR=#FFFFFF>"
Response.Write "<TR bgcolor=Firebrick align=center><TD WIDTH=70><FONT SIZE=2 COLOR=WHITE><B>项目编号</B></FONT></TD><TD WIDTH=180><FONT SIZE=2 COLOR=WHITE><B>项目名称</B></FONT></TD><TD WIDTH=90><FONT SIZE=2 COLOR=WHITE><B>需求计划单号</B></FONT></TD><TD WIDTH=90><FONT SIZE=2 COLOR=WHITE><B>需求计划编号</B></FONT></TD><TD WIDTH=60><FONT SIZE=2 COLOR=WHITE><B>申报单位</B></FONT></TD><TD WIDTH=60><FONT SIZE=2 COLOR=WHITE><B>申报日期</B></FONT></TD><TD WIDTH=60><FONT SIZE=2 COLOR=WHITE><B>下发日期</B></FONT></TD></FONT><TR BGCOLOR=#FFFFFF>"
do
while not (RS is nothing)
RowCount = RS.PageSize
do
While Not RS.EOF and rowcount > 0
If n=1 then
Response.Write "<TR BGCOLOR=#FFFFFF>"
else
Response.Write "<TR BGCOLOR=#EEEEEE>"
End If
n=1-n %>
<TD><span style="font-size:9pt"><% =RS("sItemID")%></span></td>
<TD><span style="font-size:9pt">
<%if VarType(RS("sItemName"))=1 then
%>
&amp;nbsp;&amp;nbsp;
<%else
%>
<%if len(cstr(RS("sItemName")))=0 then
%>
&amp;nbsp;&amp;nbsp;
<%end if%>
<%end if%>
<% =RS("sItemName")%></span></td>
<TD><span style="font-size:9pt"><% =RS("sPlanID")%></span></td>
<TD><span style="font-size:9pt"><% =RS("sPlanTrackNo")%></span></td>
<TD><span style="font-size:9pt"><% =RS("sDepartmentName")%></span></td>
<TD><span style="font-size:9pt"><% =RS("dReportDate")%></span></TD>
<TD><span style="font-size:9pt"><% =RS("dHandinDate")%></span></td>
</TR>
<%
RowCount = RowCount - 1
RS.MoveNext
Loop
set RS = RS.NextRecordSet
Loop

response.write "</TABLE>"
%>
<FORM METHOD=GET ACTION="11.asp" id=form1 name=form1>
<INPUT TYPE="HIDDEN" NAME="pageno" VALUE="<% =PageNo %>">
<%
if PageNo > 1 then

response.write "<INPUT TYPE=SUBMIT NAME='ScrollAction' VALUE='上一页'>"
end if
if RowCount = 0 and PageNo<>Total then

response.write "<INPUT TYPE=SUBMIT NAME='ScrollAction' VALUE='下一页'>"
end if
response.write "</FORM>"

End if
%>
<HTML>
<HEAD>
<META name="VI60_DefaultClientScript" Content="VBScript">
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<P>&amp;nbsp;</P>
</BODY>
</HTML>
 
好长,看的都头晕,给你一段我写的,看看对你有没有帮助。
<%
const MaxPerPage=10
dim totalPut
dim CurrentPage
dim TotalPages
dim i,j
dim idlist
dim title
title=request("txtitle")
if not isempty(request("page")) then
currentPage=cint(request("page"))
else
currentPage=1
end if
dim sql
dim rs
%>
<%
if title<>"" then
sql="select ********"
else
sql="Select ********"
end if
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write "<p align='center'> 还 没 有 任 何 控 件 </p>"
else
totalPut=rs.recordcount
if currentpage<1 then
currentpage=1
end if
if (currentpage-1)*MaxPerPage>totalput then
if (totalPut mod MaxPerPage)=0 then
currentpage= totalPut / MaxPerPage
else
currentpage= totalPut / MaxPerPage + 1
end if
end if
if currentPage=1 then
showpage totalput,MaxPerPage,"ctlsearch.asp"
showContent
showpage totalput,MaxPerPage,"ctlsearch.asp"
else
if (currentPage-1)*MaxPerPage<totalPut then
rs.move (currentPage-1)*MaxPerPage
dim bookmark
bookmark=rs.bookmark
showpage totalput,MaxPerPage,"ctlsearch.asp"
showContent
showpage totalput,MaxPerPage,"ctlsearch.asp"
else
currentPage=1
showpage totalput,MaxPerPage,"ctlsearch.asp"
showContent
showpage totalput,MaxPerPage,"ctlsearch.asp"
end if
end if
rs.close
end if

set rs=nothing
conn.close
set conn=nothing

sub showContent
dim i
i=0
%>
<%do while not rs.eof%>
、、、、、、这里是显示过程。。。。。就是<%=rs(***)%>。。。等的东西。
<%
i=i+1
if i>=MaxPerPage then
exitdo
rs.movenext
loop
%>

<%
end sub
function showpage(totalnumber,maxperpage,filename)
dim n
if totalnumber mod maxperpage=0 then
n= totalnumber / maxperpage
else
n= totalnumber / maxperpage+1
end if
response.write "<p align='center'>&amp;nbsp;"
if CurrentPage<2 then
response.write "<font color='#000080'>首页 上一页</font>&amp;nbsp;"
else
response.write "<a href="&amp;filename&amp;"?page=1>首页</a>&amp;nbsp;"
response.write "<a href="&amp;filename&amp;"?page="&amp;CurrentPage-1&amp;">上一页</a>&amp;nbsp;"
end if
if n-currentpage<1 then
response.write "<font color='#000080'>下一页 尾页</font>"
else
response.write "<a href="&amp;filename&amp;"?page="&amp;(CurrentPage+1)&amp;">"
response.write "下一页</a> <a href="&amp;filename&amp;"?page="&amp;n&amp;">尾页</a>"
end if
response.write "<font color='#000080'>&amp;nbsp;页次:</font><strong><font color=red>"&amp;CurrentPage&amp;"</font><font color='#000080'>/"&amp;n&amp;"</strong>页</font> "
response.write "<font color='#000080'>&amp;nbsp;共<b>"&amp;totalnumber&amp;"</b>个控件 <b>"&amp;maxperpage&amp;"</b>个控件/页</font> "

end function
%>
 
当有条件查询的时候,你没有把那个条件也包含在 翻页 中.
比如 你的以下代码.
<FORM METHOD=GET ACTION="11.asp" id=form1 name=form1>
<INPUT TYPE="HIDDEN" NAME="pageno" VALUE="<% =PageNo %>">
<input type=hidden name=department value="<%=department%>"> << === 你要加上这一句,,
 
补充一下, 在程序头部,你可以加上一些判断 department 是否为空的语句,
如果为空. WHERE PlanTable.sDepartmentID= '"&amp;department&amp;"'" 这一个条件就不必
限制了.即
可这样
temp=" WHERE PlanTable.sDepartmentID= '"&amp;department&amp;"' "
if len(department)<1 then
temp=''
而这句SQL语句也要改成
sql="SELECT *,ItemID.sItemName ,Department.sDepartmentName FROM PlanTable INNER JOIN Department ON PlanTable.sDepartmentID = Department.sDepartmentID INNER JOIN ItemID ON PlanTable.sItemID = ItemID.sItemID "&amp;temp
这样查询的时候,没有输入关銉字时可列出全部的纪录.
 
多人接受答案了。
 

Similar threads

A
回复
0
查看
623
Andreas Hausladen
A
I
回复
0
查看
754
import
I
D
回复
0
查看
945
DelphiTeacher的专栏
D
后退
顶部