一个老僧常谈的问题!!

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%>

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

...全文
75 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

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