<!-- #include file="../Inc/conn.asp" --><%dim i,intPage,page,pre,last,filepathset rs = server.CreateObject("adodb.recordset")sql="select * from user order by user_ID desc"rs.PageSize = 20 '这里设定每页显示的记录数rs.CursorLocation = 3rs.Open sql,conn,0,2,1 '这里执行你查询SQL并获得结果记录集pre = truelast = truepage = trim(Request.QueryString("page"))if len(page) = 0 thenintpage = 1pre = falseelseif cint(page) =< 1 thenintpage = 1pre = falseelseif cint(page) >= rs.PageCount thenintpage = rs.PageCountlast = falseelseintpage = cint(page)end ifend ifend ifif not rs.eof thenrs.AbsolutePage = intpageend if%><style type="text/css"><!--body,td,th {font-size: 12px;}a:link {text-decoration: none;}a:visited {text-decoration: none;}a:hover {text-decoration: none;}a:active {text-decoration: none;}--></style>循环体开始:<%for i=1 to rs.PageSizeif rs.EOF or rs.BOF then exit for%>.......................................................<%rs.movenextnext%>循环体结束分页部分:<table width="99%" border="1" cellpadding="2" cellspacing="2" borderColorLight=#808080 borderColorDark=#ffffff><tr><%if rs.pagecount > 0 then%><td width="13%" align="left">当前页<%=intpage%>/<%=rs.PageCount%></td><%else%><td width="41%" align="left">当前页0/0</td><%end if%><td width="46%" align="right"> <a href="document_manage.asp?page=1">[首页]</a>|<%if pre then%><a href="document_manage.asp?page=<%=intpage -1%>">[上页]</a>| <%end if%><%if last then%><a href="document_manage.asp?page=<%=intpage +1%>">[下页]</a> |<%end if%><a href="document_manage.asp?page=<%=rs.PageCount%>">[尾页]</a>|转到第<select name="sel_page" onchange="javascript:location=this.options[this.selectedIndex].value;"><%for i = 1 to rs.PageCountif i = intpage then%><option value="document_manage.asp?page=<%=i%>" selected><%=i%></option><%else%><option value="document_manage.asp?page=<%=i%>"><%=i%></option><%end ifnext%></select>页</font></td></tr></table>这段代码还是很好用的,只不过在设置了每页显示条数后,最后一页提示错误:ADODB.Field 错误 '***********'BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。还请各位大侠给修改一下,本菜鸟感谢不尽!
參考答案:把分页部分有关RS的东西,比如rs.PageCount换成变量
放到
if rs.EOF or rs.BOF then exit for
%>
..................
..................
...................
<%
rs.movenext
next
内,
因为你末页没记录了