<p><html><br /><title>分页技术</title><br /><head><br /><%<br /> const MaxPerPage=25<br /> dim sql <br /> dim rs<br /> dim totalPut <br /> dim CurrentPage<br /> dim TotalPages<br /> dim i,j <br />%><br /></head><br /><body bgcolor=Thistle><br /><P align=center><FONT face=方正舒体><FONT size=5><STRONG>实例&nbsp;&nbsp;&nbsp; <br />分页技术</STRONG></p><p><%<br />conn = "DBQ=" + server.mappath("mydb.mdb") + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};" <br />sql = "SELECT * FROM mytable"<br />set rs=server.createobject("adodb.recordset") <br />rs.open SQL,conn,1,1<br />rs.MoveFirst<br />rs.pagesize=MaxPerPage<br />howmanyfields=rs.Fields.Count-1</p><p>If trim(Request("Page"))<>"" then<br /> CurrentPage= CLng(request("Page")) <br /> If CurrentPage> rs.PageCount then <br /> CurrentPage = rs.PageCount <br /> End If <br />Else <br /> CurrentPage= 1 <br />End If </p><p>if rs.eof then <br /> response.write "<p align='center'> ERROR!</p>" <br />else <br /> totalPut=rs.recordcount<br /> if CurrentPage<>1 then <br /> if (currentPage-1)*MaxPerPage<totalPut then <br /> rs.move(currentPage-1)*MaxPerPage <br /> dim bookmark <br /> bookmark=rs.bookmark<br /> end if <br /> end if</p><p> dim n,k <br /> if (totalPut mod MaxPerPage)=0 then <br /> n= totalPut \ MaxPerPage<br /> else <br /> n= totalPut \ MaxPerPage + 1 <br /> end if%><br /> </FONT></FONT></P><br /><P>PAGE <%=currentpage%> OF <%=n%> 共<%=rs.recordcount%> 纪录<br /> <% k=currentPage<br /> if k<>1 then<br /> response.write "[<b>"+"<a href='index.asp?page=1'>首页</a></b>] "<br /> response.write "[<b>"+"<a href='index.asp?page="+cstr(k-1)+"'>上一页</a></b>] "<br /> else<br /> Response.Write "[首页] [上一页]"<br /> end if<br /> if k<>n then<br /> response.write "[<b>"+"<a href='index.asp?page="+cstr(k+1)+"'>下一页</a></b>] "<br /> response.write "[<b>"+"<a href='index.asp?page="+cstr(n)+"'>尾页</a></b>] "<br /> else<br /> Response.Write "[下一页] [尾页]"<br /> end if<br /> %></p><p></P></p><p><TABLE border=1 align=center><br /> <tr><br /> <%<br /> for i= 0 to howmanyfields%><br /> <TD><B><%=rs(i).name%></B></TD><br /> <%<br /> next <br /> i=0<br /> do while not rs.eof and i<maxperpage%><br /> <tr align=middle><br /> <%for j=0 to howmanyfields%><br /> <td><br /> &nbsp;<%=rs(j)%>&nbsp;<br /> </td><br /> <%next%><br /> </tr><br /> <%<br /> i=i+1<br /> rs.movenext <br /> loop<br /> %><br /></TABLE><br /><%<br />end if <br />rs.close <br />set rs=nothing <br />%><br /></body><br /></html></p> |
|