注册 登录
编程论坛 ASP技术论坛

菜鸟请教下分页的问题(已附上源码),各位高手指教下谢谢!!

w106817 发布于 2010-01-09 16:23, 449 次点击
自己做的管理系统,做分页的时候点下一页直接跳到最后一页,点第一页和上页,页面跳转数据不会变~~
谢谢各位高手指教下~~
<!--#include file="conn.asp"-->
<%
dim worktype,p
worktype=request.QueryString("worktype")
p=request.QueryString("page")
if p="" then
p=1
end if
if worktype="" then
%>
<table align="center" border="0" cellpadding="0" cellspacing="0">
 <tr>
 <td><b>欢迎使用管理系统</b></td>
 </tr>
</table>
<%
elseif worktype="add" then%>
 
<% elseif worktype="mody" then
 set rs=server.CreateObject("adodb.recordset")
 sql="select * from aa order by texttime desc"
 rs.open sql,conn,1,1
 rs.pagesize=2
 if p>rs.pagecount then
  p=rs.pagecount
 end if
 if not rs.eof then
 rs.absolutepage=int(p)
 end if
 %>
......中间是表单

 <table width="600" align="center" border="0" cellpadding="5" cellspacing="0">
<%for n=1 to rs.pagesize%>
  <tr>
   <td><%=rs("texttopic")%></td>
   <td><a href="update.asp?id=<%=rs("id")%>">编辑</td>
   <td><a href="delete.asp?id=<%=rs("id")%>">删除</td>
  </tr>
  <%
  rs.movenext
  if rs.eof then
   exit for
  end if
  next
  %>
  <tr>
  <td><%if p>1 then%><a href="mody.asp?worktype=<%=worktype%>&page=1">第一页</a>
  <a href="mody.asp?worktype=<%=worktype%>&page=<%=p-1%>">上一页</a>
  <%end if%></td>
  <td>
  <%if p<rs.pagecount then%>
  <a href="mody.asp?worktype=<%=worktype%>&page=<%=p+1%>">下一页</a>
  <a href="mody.asp?worktype=<%=worktype%>&page=<%=rs.pagecount%>">最后一页</a>
  <%end if%>
  </td>
  </tr>
</table>
<%end if
%>
3 回复
#2
孤独冷雨2010-01-09 17:04
<!--#include file="conn.asp"-->
<%
dim worktype,p
worktype=request.QueryString("worktype")

if worktype="" then
%>
<table align="center" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><b>欢迎使用管理系统</b></td>
</tr>
</table>
<%
elseif worktype="add" then%>

<% elseif worktype="mody" then
set rs=server.CreateObject("adodb.recordset")
sql="select * from aa order by texttime desc"
rs.open sql,conn,1,1
if rs.eof then
response.write"没有内容"
else

rs.pagesize=2
page=Clng(request("page"))
  if page<1 then page=1
  if page>rs.recordcount then page=rs.recordcount
   rs.absolutepage=page
%>
......中间是表单

<table width="600" align="center" border="0" cellpadding="5" cellspacing="0">
<%for n=1 to rs.pagesize%>
  <tr>
   <td><%=rs("texttopic")%></td>
   <td><a href="update.asp?id=<%=rs("id")%>">编辑</a></td>
   <td><a href="delete.asp?id=<%=rs("id")%>">删除</a></td>
  </tr>
  <%
  rs.movenext
  if rs.eof then exit for
  next
  %>
  <tr>
  <td><%if p<>1 then%><a href="mody.asp?worktype=<%=worktype%>&page=1">第一页</a>
  <a href="mody.asp?worktype=<%=worktype%>&page=<%=page-1%>">上一页</a>
  <%end if%></td>
  <td>
  <%if p<>rs.pagecount then%>
  <a href="mody.asp?worktype=<%=worktype%>&page=<%=page+1%>">下一页</a>
  <a href="mody.asp?worktype=<%=worktype%>&page=<%=rs.pagecount%>">最后一页</a>
  <%end if%>
  </td>
  </tr>
</table>
<%end if
end if
%>
#3
w1068172010-01-09 17:41
谢谢版主已经弄好了
如果不嫌我烦的话,能不能再问下我问题出在哪里?是用QueryString获取的问题吗?谢谢
#4
孤独冷雨2010-01-11 14:16
request.QueryString("worktype")
只是上一个页面传过来的变量。根据这个变量在数据库里查找符合的内容翻页。


if p="" then
p=1
end if

这个没有用。你在下面已经取值作判断了。
1