一个老僧常谈的问题!!

renlily 2004-08-02 03:13:25
<%@ Language=VBScript %>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">
</HEAD>
<BODY bgcolor="#ffffff" text="#000000">
<table width=60% border=1 align=center>
<%
on error resume next
dim rs
dim sql
dim msg_per_size
msg_per_size = 3
dim StrConn,Conn
set Conn=server.CreateObject ("adodb.connection")
StrConn = "driver={SQL Server};server=(local);UID=sa;PWD=;database=northwind"
Conn.Open strConn
set rs =server.CreateObject ("adodb.recordset")
sql = "SELECT EmployeeID ,"
sql = sql & " LastName ,"
sql = sql & " FirstName "
sql = sql & " FROM Employees"
rs.CursorLocation = 3
rs.PageSize = msg_per_size
rs.Open sql,conn,2,3
if Err.number<>0 then
Response.Write "error database" & Err.description
Err.Clear
else
if not rs.EOF then
totalrec=rs.RecordCount
if rs.RecordCount mod msg_per_size = 0 then
n = rs.RecordCount \ msg_per_size
else
n = (rs.RecordCount \ msg_per_size) + 1
end if
currentpage=Request("page")
if currentpage<>"" then
currentpage=cint(currentpage)
if currentpage < 1 then
currentpage = 1
end if
if Err.number <>"" then
Err.Clear()
currentpage = 1
end if
else
currentpage = 1
end if
if (currentpage * msg_per_size) > totalrec and not ((currentpage-1)) * msg_per_size < totalrec then
currentpage = 1
end if
rs.AbsolutePage = currentpage
rowcount = rs.PageSize
%>
<tr align=center valign=middle>
<td width=30% align=center>ID</td>
<td width=30% align=center>FirstName</td>
<td width=30% align=center>LastName</td>
</tr>
<% do while not rs.EOF and rowCount > 0 %>
<tr align=center valign=middle>
<td width=30% align=center><%=rs("EmployeeID")%></td>
<td width=30% align=center><%=rs("FirstName")%></td>
<td width=30% align=center><%=rs("LastName")%></td>
</tr>
<% rowcount = rowcount - 1 %>
<% rs.MoveNext %>
<%loop%>
<%end if
end if
rs.Close
set rs = nothing
%>
</table>
<table border=0 align=right>
<tr>
<td align=center valign=middle>
<% call listpages ()%>
</td>
</tr>
</table>
</BODY>
</HTML>
<%
sub listpages()
if n <=1 then exit sub
for i=0 to n\msg_per_size-1
for j=1 to msg_per_size
%>
<font size=2 color="#006600">
<a href="<%=Request.ServerVariables("script_name")%>?page=<%=i*msg_per_size+j %>">[<%=i*msg_per_size+j%>]</a></font>
<% next
next
EndPage=n Mod msg_per_size
for j=1 to EndPage%>

<font size=2 color="#006600">
<a href="<%=Request.ServerVariables("script_name")%>?page=<%=i*msg_per_size+j %>">[<%=i*msg_per_size+j%>]</a></font>
<% next %>
<font size=2 color=black face="arial">
Page:<%=currentpage%>/<%=n%>pages <%=msg_per_size%>notes/page Total:<%=totalrec%>notes</font>
<%end sub%>

翻页时,总显示第一页的三条记录.
不知道为什么??`

...全文
106 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kebeixueng 2004-08-02
  • 打赏
  • 举报
回复
到www.webasp.net下一个就可以了
zehao 2004-08-02
  • 打赏
  • 举报
回复
同意楼上的
xzhy80 2004-08-02
  • 打赏
  • 举报
回复
循环没减1
  • 打赏
  • 举报
回复
rowcount = rs.PageSize 这个能这么写吧
搜索一下有关于分页的代码好多的,直接套用就可以了
rehearts 2004-08-02
  • 打赏
  • 举报
回复
当下一页的时候,你的记录集没有动,(你这种分页程序需要在翻页的时候移动记录集)

if (currentPage-1)*msg_per_size<totalrec then
rs.move (currentPage-1)*msg_per_size
end if

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧