asp 分页代码 问题

plcc123 2009-08-12 10:54:01
<%

sql="select * from shi where SMT_addtwo='"&request.form("returnValue")&"'"
rs.open sql,conn,1,1

session("name")= rs("SMT_addtwo_id")
response.Write("<br>")
session("namea") =request.Form("a")
response.Write("<br>")
session("nameb") =request.Form("b")
session("namec") =request.Form("jgmc")
rs.close
set rs=nothing
sqlq="select * from jigou where JG_mc like '"&"%"&session("namec")&"%"&"' and l1_id="&session("namea")&" and hy_shi="&session("name")
set rs1=server.CreateObject("adodb.recordset")
rs1.open sqlq,conn,1,1

if rs1.eof then
response.Write("暂无任何数据")
else

if not isempty(request("page")) then
pagecount=cint(request("page"))
else
pagecount=1
end if
n=1
rs1.pagesize=5 '当前页要显示的记录数
rs1.AbsolutePage=pagecount

do while not rs1.eof
response.Write rs1("jg_mc")
response.Write ("<br>")

rs1.movenext
n=n+1
if n>rs1.pagesize then exit do
loop
%><table width="535" border="0" cellspacing="0" cellpadding="0" align="center">

<tr bgcolor="#B0CCDC">
<td height="35" bgcolor="#FFFFFF">
<div align="center"> <font size="2" face="黑体" class="a">共 <b><%=rs1.recordcount%></b> 条记录, 页次: <b><font color=red><%=pagecount%></font>/<%=rs1.pagecount%></b>,
<% if pagecount=1 and rs1.pagecount<>pagecount and rs1.pagecount<>0 then%>
<a href="?page=<%=cstr(pagecount+1)%>" class="a">[下一页]</a>
<% end if %>
<% if rs1.pagecount>1 and rs1.pagecount=pagecount then %>
<a href="?page=<%=cstr(pagecount-1)%>" class="a">
[上一页]</a>
<%end if%>
<% if pagecount<>1 and rs1.pagecount<>pagecount then%>
<a href="?page=<%=cstr(pagecount-1)%>" class="a">
[上一页]</a> <a href="?page=<%=cstr(pagecount+1)%>" class="a">
[下一页]</a>
<% end if%>
<% end if%

为什么一点下一页 就显示记录不存在呢?
...全文
167 点赞 收藏 9
写回复
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuwei_IT_love 2009-08-12
同意一楼的看法
回复
plcc123 2009-08-12
[Quote=引用 4 楼 mailbao 的回复:]
我那个分页在其它地方是不出错的,但是在这里却出错了,所以希望大家帮忙找下错误。。。。


------------------------------------------------


你說的出錯地方是指什麼?不出錯的地方又指什麼??
[/Quote]

其它地方只有一sql语句,而且查询的条件很单一,所以分页顺利,
现在因为用了多条语句, 现在分页只能看到第一页的记录,后面就显示“ADODB.Field (0x80020009)
BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。”“”“
回复
femark 2009-08-12
可用ViewState保留上下页数,总page数,选择的页数等刷新会变的参数。
回复
mailbao 2009-08-12
我那个分页在其它地方是不出错的,但是在这里却出错了,所以希望大家帮忙找下错误。。。。



------------------------------------------------


你說的出錯地方是指什麼?不出錯的地方又指什麼??
回复
plcc123 2009-08-12
[Quote=引用 2 楼 mailbao 的回复:]
參考分頁例子

HTML code<formname="form1" method="post" action=""><tablewidth="98%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#6699ff"><tr><tdheight="20" align="center"><fontcolor="#FFFFFF"><%=schORmodify%></font></td></tr><tr><tdheight="100" bgcolor="#FFFFFF"><%Const MaxPerPage=10dim totalPutdim CurrentPagedim TotalPagesdim jdim sqlifNotisempty(request("page"))then
currentPage=Cint(request("page"))else
currentPage=1endIfset rs=server.CreateObject("adodb.recordset")
rs.open"select * from [ProjectItem] where Menu_ZH like '%"&selectkey&"%' order by ID desc",conn,1,1if rs.eofAnd rs.bofthen
Response.Write"<p align='center' class='contents'> No data!</p>"else
totalPut=rs.recordcountif currentpage<1then
currentpage=1endifif (currentpage-1)*MaxPerPage>totalputthenif (totalPutmod MaxPerPage)=0then
currentpage= totalPut\ MaxPerPageelse
currentpage= totalPut\ MaxPerPage+1endifendifif currentPage=1then
showContent
showpage totalput,MaxPerPage,"index.asp"elseif (currentPage-1)*MaxPerPage<totalPutthen
rs.move (currentPage-1)*MaxPerPagedim bookmark
bookmark=rs.bookmark
showContent
showpage totalput,MaxPerPage,"index.asp"else
currentPage=1
showContent
showpage totalput,MaxPerPage,"index.asp"endifendifendifsub showContentdim i
i=0%><tablewidth="95%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC"><trbgcolor="#FFFFFF" align="center" height="20"><tdwidth="20%"><fontcolor='red'><B><%=txtId%></B></font></td><tdwidth="30%"><fontcolor='red'><B><%=txtName%>Menu_ZH</B></font></td><tdwidth="40%"><fontcolor='red'><B><%=txtName%>Menu_EN</B></font></td><tdwidth="10%"><fontcolor='red'><B><%=selectBt%></B></font></td></tr><%dowhilenot rs.eof%><trbgcolor="#FFFFFF" align="center"><td><%=rs("ID")%></td><tdalign="left"><ahref=edit.asp?id=<%=rs("ID")%>><%=rs("Menu_ZH")%></a></td><tdalign="left"><ahref=edit.asp?id=<%=rs("ID")%>><%=rs("Menu_EN")%></a></td><td><inputname="selectid" type="checkbox" id="selectid" value="<%=rs("ID")%>"></td></tr><%i=i+1if i>=MaxPerPagethenExitDo
rs.movenextloop
rs.closeset rs=nothing%><trbgcolor="#FFFFFF"><tdheight="30" colspan="3" align="right"><%=selectAll%><inputtype="checkbox" name=chkallonClick="CheckAll(this.form)"> <inputtype="submit" name="action" class="button"value="<%=delBt%>" onClick="{if(confirm('Are you sure delete?')){this.document.Prodlist.submit();return true;}return false;}"></td></tr><trbgcolor="#EEEEEE"><tdcolspan="3"><%End SubFunction showpage(totalnumber,maxperpage,filename)Dim nIf totalnumberMod maxperpage=0Then
n= totalnumber\ maxperpageElse
n= totalnumber\ maxperpage+1EndIf

Response.Write"<form method=Post action="&filename&"?selectm="&selectm&"&selectkey="&selectkey&" >"
Response.Write"<p align='center' class='contents'>"If CurrentPage<2Then
Response.Write"<font class='contents'>首頁 上頁</font>"Else
Response.Write"<a href="&filename&"?page=1&selectm="&selectm&"&selectkey="&selectkey&" class='contents'>首頁</a>"
Response.Write"<a href="&filename&"?page="¤tPage-1&"&selectm="&selectm&"&selectkey="&selectkey&" class='contents'>上頁</a>"EndIfIf n-currentpage<1Then
Response.Write"<font class='contents'>下頁 尾頁</font>"Else
Response.Write"<a href="&filename&"?page="&(CurrentPage+1)&"&selectm="&selectm&"&selectkey="&selectkey&" class='contents'>"
Response.Write"下頁</a> <a href="&filename&"?page="&n&"&selectm="&selectm&"&selectkey="&selectkey&" class='contents'>尾頁</a>"EndIf
Response.Write"<font class='contents'> 當前</font><font class='contents'>"¤tPage&"</font><font class='contents'>/"&n&"頁</font>"
Response.Write"<font class='contents'> 總記錄("&totalnumber&")   "
Response.Write"<font class='contents'> 跳至</font><input type='text' name='page' size=2 maxlength=10 class=smallInput value="¤tpage&">"
Response.Write" <input type='submit' class='button' value='翻轉分頁' name='cndok' ></form>"End Function%></td></tr></table></td></tr></table></form>
[/Quote]


我那个分页在其它地方是不出错的,但是在这里却出错了,所以希望大家帮忙找下错误。。。。
回复
mailbao 2009-08-12
參考分頁例子


<form name="form1" method="post" action="">
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#6699ff">
<tr>
<td height="20" align="center"><font color="#FFFFFF"><%=schORmodify%></font></td>
</tr>
<tr>
<td height="100" bgcolor="#FFFFFF">
<%
Const MaxPerPage=10
dim totalPut
dim CurrentPage
dim TotalPages
dim j
dim sql
if Not isempty(request("page")) then
currentPage=Cint(request("page"))
else
currentPage=1
end If
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from [ProjectItem] where Menu_ZH like '%"&selectkey&"%' order by ID desc",conn,1,1
if rs.eof And rs.bof then
Response.Write "<p align='center' class='contents'> No data!</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
showContent
showpage totalput,MaxPerPage,"index.asp"
else
if (currentPage-1)*MaxPerPage<totalPut then
rs.move (currentPage-1)*MaxPerPage
dim bookmark
bookmark=rs.bookmark
showContent
showpage totalput,MaxPerPage,"index.asp"
else
currentPage=1
showContent
showpage totalput,MaxPerPage,"index.asp"
end if
end if
end if

sub showContent
dim i
i=0%>
<table width="95%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
<tr bgcolor="#FFFFFF" align="center" height="20">
<td width="20%"><font color='red'><B><%=txtId%></B></font></td>
<td width="30%"><font color='red'><B><%=txtName%>Menu_ZH</B></font></td>
<td width="40%"><font color='red'><B><%=txtName%>Menu_EN</B></font></td>
<td width="10%"><font color='red'><B><%=selectBt%></B></font></td>
</tr>
<%do while not rs.eof%>
<tr bgcolor="#FFFFFF" align="center">
<td><%=rs("ID")%></td>
<td align="left"><a href=edit.asp?id=<%=rs("ID")%>><%=rs("Menu_ZH")%></a></td>
<td align="left"><a href=edit.asp?id=<%=rs("ID")%>><%=rs("Menu_EN")%></a></td>
<td><input name="selectid" type="checkbox" id="selectid" value="<%=rs("ID")%>"></td>
</tr>
<%i=i+1
if i>=MaxPerPage then Exit Do
rs.movenext
loop
rs.close
set rs=nothing%>
<tr bgcolor="#FFFFFF">
<td height="30" colspan="3" align="right"><%=selectAll%> <input type="checkbox" name=chkall onClick="CheckAll(this.form)"> <input type="submit" name="action" class="button"value="<%=delBt%>" onClick="{if(confirm('Are you sure delete?')){this.document.Prodlist.submit();return true;}return false;}"></td>
</tr>
<tr bgcolor="#EEEEEE">
<td colspan="3">
<%
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 "<form method=Post action="&filename&"?selectm="&selectm&"&selectkey="&selectkey&" >"
Response.Write "<p align='center' class='contents'> "
If CurrentPage<2 Then
Response.Write "<font class='contents'>首頁 上頁</font> "
Else
Response.Write "<a href="&filename&"?page=1&selectm="&selectm&"&selectkey="&selectkey&" class='contents'>首頁</a> "
Response.Write "<a href="&filename&"?page="¤tPage-1&"&selectm="&selectm&"&selectkey="&selectkey&" class='contents'>上頁</a> "
End If

If n-currentpage<1 Then
Response.Write "<font class='contents'>下頁 尾頁</font>"
Else
Response.Write "<a href="&filename&"?page="&(CurrentPage+1)&"&selectm="&selectm&"&selectkey="&selectkey&" class='contents'>"
Response.Write "下頁</a> <a href="&filename&"?page="&n&"&selectm="&selectm&"&selectkey="&selectkey&" class='contents'>尾頁</a>"
End If
Response.Write "<font class='contents'> 當前</font><font class='contents'>"¤tPage&"</font><font class='contents'>/"&n&"頁</font> "
Response.Write "<font class='contents'> 總記錄("&totalnumber&")   "
Response.Write "<font class='contents'> 跳至</font><input type='text' name='page' size=2 maxlength=10 class=smallInput value="¤tpage&">"
Response.Write " <input type='submit' class='button' value='翻轉分頁' name='cndok' ></form>"
End Function
%>
</td>
</tr>
</table>
</td>
</tr>
</table></form>

回复
shenzhenNBA 2009-08-12
核心提示:当点击翻页(首页尾页上一页下一页)是要记得把搜索的/查找的/查询的条件也传递下去,
回复
plcc123 2009-08-12
问题解决了

sql="select * from shi where SMT_addtwo='"&request.form("returnValue")&"'"
rs.open sql,conn,1,1
if not rs.eof then '加了这个判断,就没错了 !!
session("name")= rs("SMT_addtwo_id")
response.Write(" <br>")
session("namea") =request.Form("a")
response.Write(" <br>")
session("nameb") =request.Form("b")
session("namec") =request.Form("jgmc")
回复
plcc123 2009-08-12
问题解决了

sql="select * from shi where SMT_addtwo='"&request.form("returnValue")&"'"
rs.open sql,conn,1,1
if not rs.eof then '加了这个判断,就没错了 !!
session("name")= rs("SMT_addtwo_id")
response.Write(" <br>")
session("namea") =request.Form("a")
response.Write(" <br>")
session("nameb") =request.Form("b")
session("namec") =request.Form("jgmc")
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告