热搜词
发表于 2008-2-28 21:29:00 | 显示全部楼层 |阅读模式
<p>&lt;html&gt;<br />&lt;title&gt;分页技术&lt;/title&gt;<br />&lt;head&gt;<br />&lt;%<br />&nbsp;&nbsp; const MaxPerPage=25<br />&nbsp;&nbsp; dim sql <br />&nbsp;&nbsp; dim rs<br />&nbsp;&nbsp; dim totalPut&nbsp;&nbsp; <br />&nbsp;&nbsp; dim CurrentPage<br />&nbsp;&nbsp; dim TotalPages<br />&nbsp;&nbsp; dim i,j <br />%&gt;<br />&lt;/head&gt;<br />&lt;body bgcolor=Thistle&gt;<br />&lt;P align=center&gt;&lt;FONT face=方正舒体&gt;&lt;FONT size=5&gt;&lt;STRONG&gt;实例&amp;nbsp;&amp;nbsp;&amp;nbsp; <br />分页技术&lt;/STRONG&gt;</p><p>&lt;%<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"))&lt;&gt;"" then<br />&nbsp;CurrentPage= CLng(request("Page")) <br />&nbsp;If CurrentPage&gt; rs.PageCount then <br />&nbsp;&nbsp;CurrentPage = rs.PageCount <br />&nbsp;End If <br />Else <br />&nbsp;CurrentPage= 1 <br />End If </p><p>if rs.eof then <br />&nbsp;response.write "&lt;p align=&#39;center&#39;&gt; ERROR!&lt;/p&gt;" <br />else <br />&nbsp;totalPut=rs.recordcount<br />&nbsp;if CurrentPage&lt;&gt;1 then <br />&nbsp;&nbsp;if (currentPage-1)*MaxPerPage&lt;totalPut then <br />&nbsp;&nbsp;&nbsp;rs.move(currentPage-1)*MaxPerPage <br />&nbsp;&nbsp;&nbsp;dim bookmark <br />&nbsp;&nbsp;&nbsp;bookmark=rs.bookmark<br />&nbsp;&nbsp;end if <br />&nbsp;end if</p><p>&nbsp;dim n,k <br />&nbsp;if (totalPut mod MaxPerPage)=0 then&nbsp; <br />&nbsp;&nbsp;n= totalPut &#92; MaxPerPage<br />&nbsp;else&nbsp; <br />&nbsp;&nbsp;n= totalPut &#92; MaxPerPage + 1&nbsp; <br />&nbsp;end if%&gt;<br />&nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;<br />&lt;P&gt;PAGE &lt;%=currentpage%&gt; OF &lt;%=n%&gt;&nbsp;&nbsp; 共&lt;%=rs.recordcount%&gt; 纪录<br />&nbsp;&lt;%&nbsp;k=currentPage<br />&nbsp;&nbsp;if k&lt;&gt;1 then<br />&nbsp;&nbsp;&nbsp;response.write "[&lt;b&gt;"+"&lt;a href=&#39;index.asp?page=1&#39;&gt;首页&lt;/a&gt;&lt;/b&gt;] "<br />&nbsp;&nbsp;&nbsp;response.write "[&lt;b&gt;"+"&lt;a href=&#39;index.asp?page="+cstr(k-1)+"&#39;&gt;上一页&lt;/a&gt;&lt;/b&gt;] "<br />&nbsp;&nbsp;else<br />&nbsp;&nbsp;&nbsp;Response.Write "[首页] [上一页]"<br />&nbsp;&nbsp;end if<br />&nbsp;&nbsp;if k&lt;&gt;n then<br />&nbsp;&nbsp;&nbsp;response.write "[&lt;b&gt;"+"&lt;a href=&#39;index.asp?page="+cstr(k+1)+"&#39;&gt;下一页&lt;/a&gt;&lt;/b&gt;] "<br />&nbsp;&nbsp;&nbsp;response.write "[&lt;b&gt;"+"&lt;a href=&#39;index.asp?page="+cstr(n)+"&#39;&gt;尾页&lt;/a&gt;&lt;/b&gt;] "<br />&nbsp;&nbsp;else<br />&nbsp;&nbsp;&nbsp;Response.Write "[下一页] [尾页]"<br />&nbsp;&nbsp;end if<br />&nbsp;%&gt;</p><p>&lt;/P&gt;</p><p>&lt;TABLE border=1 align=center&gt;<br />&nbsp;&lt;tr&gt;<br />&nbsp;&lt;%<br />&nbsp;for i= 0 to howmanyfields%&gt;<br />&nbsp;&nbsp;&lt;TD&gt;&lt;B&gt;&lt;%=rs(i).name%&gt;&lt;/B&gt;&lt;/TD&gt;<br />&nbsp;&lt;%<br />&nbsp;next&nbsp;<br />&nbsp;i=0<br />&nbsp;do while not rs.eof and i&lt;maxperpage%&gt;<br />&nbsp;&lt;tr align=middle&gt;<br />&nbsp;&nbsp;&lt;%for j=0 to howmanyfields%&gt;<br />&nbsp;&nbsp;&lt;td&gt;<br />&nbsp;&nbsp;&nbsp;&amp;nbsp;&lt;%=rs(j)%&gt;&amp;nbsp;<br />&nbsp;&nbsp;&lt;/td&gt;<br />&nbsp;&nbsp;&lt;%next%&gt;<br />&nbsp;&lt;/tr&gt;<br />&nbsp;&lt;%<br />&nbsp;i=i+1<br />&nbsp;rs.movenext <br />&nbsp;loop<br />&nbsp;%&gt;<br />&lt;/TABLE&gt;<br />&lt;%<br />end if <br />rs.close <br />set rs=nothing <br />%&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;</p>
全部评论1
回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|小黑屋|管理员之家 ( 苏ICP备2023053177号-2 )

GMT+8, 2024-11-25 06:47 , Processed in 0.192287 second(s), 22 queries .

Powered by Discuz! X3.5

Cpoyright © 2001-2024 Discuz! Team