100分求下面问题的解答!急!急!关于分页显示

fatality1977 2002-05-15 03:58:33
我在编程时使用了一个分页显示查询结果的例程,当需要分页显示时采用了如下的形式:http://xxx/xxx.asp?page=1(2,3....),其中xxx.asp为查询结果的当前页。有个问题就是:由于采用这种方法,无法保存由上一页面提交的变量值,所以不能进行正确的分页显示。请问如何解决这个问题?谢谢!!!!
...全文
11 点赞 收藏 13
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
zhenhao 2002-05-15
这是我的分页显示的程序,可能不是最好的,但是可以用。


<%
dim Page
rs.PageSize=20
Page=clng(Request("Page"))
if Page < 1 then Page = 1
if Page > rs.PageCount then Page = rs.PageCount
ShowOnePage rs,Page
%>
<%
if Page <> 1 then
Response.Write "<a href=show.asp?Page=1>第一页</a>" & " "
Response.Write "<a href=show.asp?page=" & (Page-1) & ">上一页</a>" & "  "
'Response.Write "<a href=addstu.asp>添加学生</a>"
end if
if Page<>rs.PageCount then
Response.Write "<a href=show.asp?Page=" & (Page+1) & ">下一页</a>" & " "
Response.Write "<a href=show.asp?Page=" & rs.PageCount & "> 最后一页</a>" & "  "
Response.Write "<a href=addstu1.asp>添加档案</a>" & "  "
Response.Write "<a href=select1.asp>查找档案</a>"

end if
if Page=rs.PageCount then
Response.Write "<a href=addstu1.asp>添加档案</a>" & "  "
Response.Write "<a href=select1.asp>查找档案</a>"

end if
%>
<p>输入页数:<input type="text" name="Page" size="3"> 页数:<font color="red"><% = Page%>/<% = rs.PageCount%></font>
</p>
</form>
</div>
<p>
</p>
<%
sub ShowOnePage(rs,Page)
'set rs=server.CreateObject("adodb.recordset")
'Response.Write "<form action='info.asp' method=post>"
Response.Write "<center><table border=4 bordercolor=orange>"
Response.Write "<tr bgcolor=orange>"
Response.Write "<td><font color=white><b>编号</b></font></td>"
for i=0 to rs.Fields.Count-1
'Response.Write "<td><font color=white><b>" & "学号" & "</b></font></td>"
'Response.Write "<td><font color=white><b>" & "姓名" & "</b></font></td>"
'Response.Write "<td><font color=white><b>" & "班号" & "</b></font></td>"
'Response.Write "<td><font color=white><b>" & "性别" & "</b></font></td>"
'Response.Write "<td><font color=white><b>" & "政治面貌" & "</b></font></td>"
'Response.Write "<td><font color=white><b>" & "专业" & "</b></font></td>"
'Response.Write "<td><font color=white><b>" & "培养方式" & "</b></font></td>"
Response.Write "<td><font color=white><b>" & rs.Fields(i).Name & "</b></font></td>"
'Response.Write "<td><font color=white><b>" & "删除" & "</b></font></td>"
'rs.Fields(i).Name
next
Response.Write "<td><font color=white><b>" & "删除" & "</b></font></td>"
Response.Write "</tr>"
rs.AbsolutePage=Page
'for iPage=1 to rs.pagesize
for iPage=1 to rs.PageSize
Response.Write "<tr align=middle>"
RecNo=(Page-1) * rs.PageSize + iPage
Response.Write "<td>" & RecNo & "</td>"
for i=0 to rs.fields.count-1
'if i=1 then
'Response.Write "<td><a href=info.asp?button_sc=detail>" & RecNo & ">" & rs(i).value & "</td>"
'else
Response.Write "<td>" & rs.Fields(i).Value & "</td>"
' Response.Write "<td>" & rs.Fields("学号").Value & "</td>"
' Response.Write "<td>" & rs.Fields("姓名").Value & "</td>"
' Response.Write "<td>" & rs.Fields("班号").Value & "</td>"
' Response.Write "<td>" & rs.Fields("性别").Value & "</td>"
' Response.Write "<td>" & rs.Fields("政治面貌").Value & "</td>"
' Response.Write "<td>" & rs.Fields("专业").Value & "</td>"
' Response.Write "<td>" & rs.Fields("培养方式").Value & "</td>"
' Response.Write "<td><a href=info.asp?button_sc=detail" & RecNo & "&Page=" & Page & ">" & "详细资料" & "</td>"
'Response.Write "<td><a href=delete.asp?button_sc=detail" & rs.Fields(0).value & ">" & "删除" & "</td>"

'end if
next
Response.Write "<td><a href=delete.asp?button_sc=detail" & rs.Fields(0).value & ">" & "删除" & "</td>"
Response.Write "</tr>"
rs.MoveNext
if rs.EOF then exit for
next
Response.Write "</table></center>"
'</form>"
end sub

%>
回复
tripofdream 2002-05-15
用QueryString传值确实有长度限制,只能用session传值了.
回复
希偌 2002-05-15
我有个例子,我一直用的方法!
<%
set conn=server.createobject("ADODB.CONNECTION")
conn.open "provider=sqloledb;data source=172.18.24.246;uid=sa;pws=;database=netmanage_test"
'conn.open "provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("net.mdb")

const intpagesize=20
if trim(Request("page"))="" then
intcur=1
else
intcur=cint(request("curpage"))
select case request("page")
case "first"
intcur=1
case "privious"
intcur=intcur-1
case "next"
intcur=intcur+1
case "last"
intcur=cint(request("lastpage"))
case else
intcur=request("page")
end select
end if
set rs=server.createobject("ADODB.recordset")
rs.CacheSize=intpagesize
sql="select * from tt order by id desc"
rs.open sql,conn,1,1
rs.PageSize=intpagesize
if Not rs.EOF then
rs.AbsolutePage=intcur
end if
inttotal=rs.pagecount
session("inttotal")=inttotal
rscount=rs.recordcount
%>
<% if intcur>1 then %>
<a href="-search.asp?sel1=<%=request("sel1")%>&sel2=<%=request("sel2")%>&sel3=<%=request("sel3")%>&sel4=<%=request("sel4")%>&curpage=<%=intcur%>&lastpage=<%=inttotal%>&page=first"><<--首页</a>||<a href="-search.asp?sel1=<%=request("sel1")%>&sel2=<%=request("sel2")%>&sel3=<%=request("sel3")%>&sel4=<%=request("sel4")%>&curpage=<%=intcur%>&lastpage=<%=inttotal%>&page=privious"><-上一页</a>|
<% end if %>
<% if cint(intcur)<cint(inttotal) then %>
|<a href="-search.asp?sel1=<%=request("sel1")%>&sel2=<%=request("sel2")%>&sel3=<%=request("sel3")%>&sel4=<%=request("sel4")%>&curpage=<%=intcur%>&lastpage=<%=inttotal%>&page=next">下一页-></a>||<a href="-search.asp?sel1=<%=request("sel1")%>&sel2=<%=request("sel2")%>&sel3=<%=request("sel3")%>&sel4=<%=request("sel4")%>&curpage=<%=intcur%>&lastpage=<%=inttotal%>&page=last">尾页-->></a>
<% end if %>
回复
wt423 2002-05-15
不可能
要么你就用第二种方法!
回复
fatality1977 2002-05-15
我尝试过这种办法。由于我需要传递的变量很多,有10个变量值,所以写得很长。象:xxx.asp?page=1?a=xx?b=xx?c=xx?.....但到了一定的长度以后好象就不行了。:(
回复
wangfei2428 2002-05-15
就是嘛
<%
for i=1 to rs.pagecount

<a href=xxx.asp?page="&i&"&key="&key&">"&i&" </a>

next
%>
回复
wt423 2002-05-15
简单!简单!!
将上一页面提交的变量值一同递交到本页
例如:
http://xxx/xxx.asp?page=页码&name=name&...
另外还有种方法:
(假如你接受上一页的变量后是为了将其处理后生成查询语句的话)
例如你生成的查询语句为:sql
只需要使用这样一句:
pathsql=server.URLPathEncode(sql)
然后:
http://xxx/xxx.asp?page=页码&sql=<%=pathsql%>
就可以了!!:)
回复
wangfei2428 2002-05-15
就是嘛
<%
for i=1 to rs.pagecount

<a href=xxx.asp?page="&i&"&key="&key&">"&i&" </a>

next
%>
回复
yyy_er 2002-05-15
我是将查询条件的sql语句(where...)存到一个session变量里
如果显示全部,则清空它
这不是最好的方法,但是习惯了

如上说的,你可以将查询变量通Query变量一直在分页的每页里传递
回复
wang_hui 2002-05-15
xxx.asp?page = <% =current_page %>
回复
apoint 2002-05-15
楼上的对
回复
ChinaOk 2002-05-15
既然能传递page,那也就能传其他的了。呵呵
ll.asp?page=2&key=varkey
回复
popcode 2002-05-15
用request.querystring
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2002-05-15 03:58
社区公告
暂无公告