asp分页的问题
<%dimcon,rssetcon=server.createobject("adodb.connection")setrs=server.createobject("a...
<%
dim con,rs
set con=server.createobject("adodb.connection")
set rs=server.createobject("adodb.recordset")
con.open="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs"
on error resume next
rs.cursortype=adopenstatic
rs.open"select * from jobs",con
if rs.recordcount=0 then
response.write"<p><center>对不起,数据库中没有相关信息</center></p>"
else
rs.pagesize=5
on error resume next
page=clng(request("page"))
if page<1 then page=1
if page>rs.pagecount then page=rs.pagecount
%>
<table border=1>
<tr>
<td>序号</td>
<%
for i=0 to rs.fields.count-1
response.write"<td>"& rs.fields(i).name &"</td>"
next
%>
</tr>
<%
rs.absolutepage=page
for ipage=1 to rs.pagesize
recNo=(page - 1)* rs.pagesize+ipage
%>
<tr>
<td><%=recno%></td>
<%for i=0 to rs.fields.count-1%>
<td><%=rs.fields(i).value%></td>
<%next%>
</tr>
<%
rs.movenext
if rs.eof then exit for
next
%>
</table>
<p align="center">
<%
if page<>1 then
response.write"<a href=viewdata.asp?page=1>第一页</a> "
response.write"<a href=viewdata.asp?page=&(page-1)&>上一页</a> "
end if
if page<>rs.pagecount then
response.write"<a href=viewdata.asp?page="&(page+1)&">下一页</a> "
response.write"<a href=viewdata.asp?page="& rs.pagecount &">最后一页</a>;"
end if
%>
</p>
<p align="center">
<%=rs.pagecount%>
<%=page%><%rs=pagecount%>
</p>
<%
end if
rs.close
conn.close
set rs=nothing
set conn=nothing
%>
问题:现在只能显示一页,实际应该显示3页的,帮我看看哪里的代码错了 展开
dim con,rs
set con=server.createobject("adodb.connection")
set rs=server.createobject("adodb.recordset")
con.open="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs"
on error resume next
rs.cursortype=adopenstatic
rs.open"select * from jobs",con
if rs.recordcount=0 then
response.write"<p><center>对不起,数据库中没有相关信息</center></p>"
else
rs.pagesize=5
on error resume next
page=clng(request("page"))
if page<1 then page=1
if page>rs.pagecount then page=rs.pagecount
%>
<table border=1>
<tr>
<td>序号</td>
<%
for i=0 to rs.fields.count-1
response.write"<td>"& rs.fields(i).name &"</td>"
next
%>
</tr>
<%
rs.absolutepage=page
for ipage=1 to rs.pagesize
recNo=(page - 1)* rs.pagesize+ipage
%>
<tr>
<td><%=recno%></td>
<%for i=0 to rs.fields.count-1%>
<td><%=rs.fields(i).value%></td>
<%next%>
</tr>
<%
rs.movenext
if rs.eof then exit for
next
%>
</table>
<p align="center">
<%
if page<>1 then
response.write"<a href=viewdata.asp?page=1>第一页</a> "
response.write"<a href=viewdata.asp?page=&(page-1)&>上一页</a> "
end if
if page<>rs.pagecount then
response.write"<a href=viewdata.asp?page="&(page+1)&">下一页</a> "
response.write"<a href=viewdata.asp?page="& rs.pagecount &">最后一页</a>;"
end if
%>
</p>
<p align="center">
<%=rs.pagecount%>
<%=page%><%rs=pagecount%>
</p>
<%
end if
rs.close
conn.close
set rs=nothing
set conn=nothing
%>
问题:现在只能显示一页,实际应该显示3页的,帮我看看哪里的代码错了 展开
展开全部
代码可能用这个我用起没得问题哈!
<table width="80" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#999999">
<% '分页代码
if err.number<>0 then
response.write("操作数据库失败")&err.description
elseif rs.eof or rs.bof then
response.write("数据库暂时没有数据")
end if
'设置buffer为True
Response.Buffer = True
'开始错误处理
On Error Resume Next
'错误处理
If Err.Number <> 0 Then
'清除页面
Response.Clear
'显示错误信息给用户
end if
%>
<%
rs.PageSize = 10
page = CLng(Request.QueryString("page"))
If page < 1 Then
page = 1
End If
If page > rs.PageCount Then
page = rs.PageCount
End If
rs.AbsolutePage = page
%>
<% w=rs.recordcount%>
<tr>
<td width="38" height="18"><div align="center">序号</div></td>
<td width="36"><div align="center"></div> <div align="center"></div> </td>
</tr>
<% i=1
do while i<=rs.PageSize and rs.Eof=false
%>
<tr>
<td height="31"><div align="center"><%=rs.fields("id")%></div></td>
<td><div align="center"><%=rs.fields(i).value%></div> <div align="center"></div></td>
</tr>
<%
rs.MoveNext
i=i+1
Loop
%>
</table>
<table width="800" height="20" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center">
<%
If page = 1 Then
Response.Write(" 首页 ")
Else
Response.Write(" <a href=viewlink.asp?page=1>首页</a> ")
End If
'设置“上一页”链接
If page = 1 Then
Response.Write(" 上一页 ")
Else
Response.Write(" <a href=viewlink.asp?page=" & page-1 & ">上一页</a> ")
End If
response.write(" 当前为第")%>
<font color="red">
<%response.write(page)%>
</font>
<%response.write("页 ")
'设置“下一页”链接
If page = rs.PageCount Then
Response.Write(" 下一页 ")
Else
Response.Write(" <a href=viewlink.asp?page=" & page+1 & ">下一页</a> ")
End If
'设置“最后一页”链接
If page = rs.PageCount Then
Response.Write(" 末页 ")
Else
Response.Write(" <a href=viewlink.asp?page=" & rs.PageCount &">末页</a> ")
End If
d=rs.pagecount
'断开与数据库的连接
Conn.Close
If Conn.State = 0 Then
End If
'释放Connection对象,关闭数据库
Set Conn = nothing
%>
共<font color="red"><%=d%></font>页 共<font color="red"><%= w %></font>条信息 </div></td>
</tr>
</table>
<table width="80" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#999999">
<% '分页代码
if err.number<>0 then
response.write("操作数据库失败")&err.description
elseif rs.eof or rs.bof then
response.write("数据库暂时没有数据")
end if
'设置buffer为True
Response.Buffer = True
'开始错误处理
On Error Resume Next
'错误处理
If Err.Number <> 0 Then
'清除页面
Response.Clear
'显示错误信息给用户
end if
%>
<%
rs.PageSize = 10
page = CLng(Request.QueryString("page"))
If page < 1 Then
page = 1
End If
If page > rs.PageCount Then
page = rs.PageCount
End If
rs.AbsolutePage = page
%>
<% w=rs.recordcount%>
<tr>
<td width="38" height="18"><div align="center">序号</div></td>
<td width="36"><div align="center"></div> <div align="center"></div> </td>
</tr>
<% i=1
do while i<=rs.PageSize and rs.Eof=false
%>
<tr>
<td height="31"><div align="center"><%=rs.fields("id")%></div></td>
<td><div align="center"><%=rs.fields(i).value%></div> <div align="center"></div></td>
</tr>
<%
rs.MoveNext
i=i+1
Loop
%>
</table>
<table width="800" height="20" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center">
<%
If page = 1 Then
Response.Write(" 首页 ")
Else
Response.Write(" <a href=viewlink.asp?page=1>首页</a> ")
End If
'设置“上一页”链接
If page = 1 Then
Response.Write(" 上一页 ")
Else
Response.Write(" <a href=viewlink.asp?page=" & page-1 & ">上一页</a> ")
End If
response.write(" 当前为第")%>
<font color="red">
<%response.write(page)%>
</font>
<%response.write("页 ")
'设置“下一页”链接
If page = rs.PageCount Then
Response.Write(" 下一页 ")
Else
Response.Write(" <a href=viewlink.asp?page=" & page+1 & ">下一页</a> ")
End If
'设置“最后一页”链接
If page = rs.PageCount Then
Response.Write(" 末页 ")
Else
Response.Write(" <a href=viewlink.asp?page=" & rs.PageCount &">末页</a> ")
End If
d=rs.pagecount
'断开与数据库的连接
Conn.Close
If Conn.State = 0 Then
End If
'释放Connection对象,关闭数据库
Set Conn = nothing
%>
共<font color="red"><%=d%></font>页 共<font color="red"><%= w %></font>条信息 </div></td>
</tr>
</table>
参考资料: www.35eb.com
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询