用RecordSet实现分页(by Daniel Adrian)

Paging through a recordset
by Daniel Adrian

Skill level: Beginner

First posted: Monday, October 09, 2000

Paging through a recordset

When I want to develop an application with a lot of records to show, I make pages so I can easily navigate
through the database and make the page look good and load quickly.

This can be done very easily. Shall we start?

Take a look at these next lines of code:

If Request.QueryString("Page") = "" Then
        Page = 1
    Else
        Page = Request.QueryString("Page")
    End If

    recordsToShow = 20
   n = 0

These lines of code are saying if the value of Request.QueryString("Page") is without any value then page
=1 else page gets the page the user requested. Recordstoshow is the number of lines in each page.
N is number of records printed.

Now lets put it into action:
objrs.PageSize = recordsToShow

(objrs is ADODB.Recordset Object)

In pagesize we are telling the record set that every page will have 20 records because recordstoshow is 20.

Now let’s pull out some records:

Do until objrs.EOF
if n = recordsToShow then
exit do
end if
write what that you want here
n=n+1
loop

Now we are writing date for the database and every time that we are repeating the loop we check if we done
it 20 times some when it’s 20 we will stop the loop.

Now let’s write the navigation:

if Page <> 1 then
Response.Write "<a href=pagename.asp?currentPage=" & currentPage - 1 &">"
end if
Response.Write "<< Back "

   if Page <> 1 then
   Response.Write "</a>"
   end if

'-------------------------
  For intCount = 1 to objRs.PageCount
   
   If intCount = 1 then
      Response.Write " | "
   End If
   
   If cint(intCount) = cint(Page) then
      Response.Write "<font color=darkblue><b>" & intCount & "</b></font> | "
   Else
Response.Write "<a hr ef=pagename.asp?currentPage=" & intCount & """>" & intCount & "</a> | "
   End If
   
Next
'-------------------------
if cint(page) = cint(objRs.PageCount) then
Response.Write "<a href=pagename.asp?currentPage=" & currentPage + 1 & ">"
end if
Response.Write " Next >> "
if cint(Page) = cint(objRs.PageCount) then
Response.Write "</a>"
end if

First we are checking if the current page is not 1 so it’s more then one so we can go back.

After this we need to write all of the pages in the record set.
Now we need to check if we can do next.

That is all! Yes it’s that easy!

时间: 2024-09-09 17:35:48

用RecordSet实现分页(by Daniel Adrian)的相关文章

ASP Recordset 分页出现负数解决方法及建议

对于Recordset分页时出现负数的现象,相信会有很多人遇到过这个问题,有时百度.GOOGLE也不得其解,现在由我来总结一下. 出现负数,主要和游标类型有关系.(为举例方便,假设已经有一个conn.asp链接数据库的文件并且已经include)现在举一个例子,代码如下: '=======================================================           sql="Select * from 表名 where 条件 order by ID des

ASP Recordset分页出现负数的解决方法

对于Recordset分页时出现负数的现象,相信会有很多人遇到过这个问题,有 时百度.GOOGLE也不得其解,现在由我来总结一下. 出现负数,主要和游标类型有关系.(为举例方便,假设已经有一个conn.asp 链接数据库的文件并且已经include)现在举一个例子,代码如下: '======================================================= sql="Select * from 表名 where 条件 order by ID desc"

关于 分页出现负数解决方法及建议

对于Recordset分页时出现负数的现象,相信会有很多人遇到过这个问题,有时百度.GOOGLE也不得其解,现在由我来总结一下. 出现负数,主要和游标类型有关系.(为举例方便,假设已经有一个conn.asp链接数据库的文件并且已经include)现在举一个例子,代码如下: 对于Recordset分页时出现负数的现象,相信会有很多人遇到过这个问题,有时百度.GOOGLE也不得其解,现在由我来总结一下. 出现负数,主要和游标类型有关系.(为举例方便,假设已经有一个conn.asp链接数据库的文件并且

分页类

分页 根据ado纪录集自动生成列表和分页,需要先生成recordset:rs_Grid<%'==========================================================='分页类,大体思想由.Net的DataGrid的使用方式而来'功能:自动生成datagrid列表头和内容,以及分页栏'根据网友bubuy (澎湃 NoMoneyToBuy)得分页函数修改成类'使用示例:'dim DG'dim Url'dim Fld(2)'dim FldName(2)'di

ASP中几种分页显示的比较

比较|分页|显示 下面通过对比来看看几种方式的用时对比. 一,使用存储过程分页,这种情况又分为两种方式: 第一种,使用command对象,如下: SetCmd=server.CreateObject("Adodb.Command") Cmd.ActiveConnection=conn Cmd.CommandText="ycuu_gb_getmsg" Cmd.CommandType=4'adCmdStoredProc cmd.prepared=true' setpar

超级ASP大分页_我的类容我做主_应用技巧

超级ASP大分页_我的类容我做主     选择自 AppleBBS 的 Blog   关键字   超级ASP大分页_我的类容我做主  出处   <%  '===================================================================  'ShowMorePage ASP版本  'Version HuangJM1.00  'Code by maomao  'Create Date 2004-09-28  'QQ:5144707  'http:

[数据库] 通用分页存储过程第1/5页_数据库其它

分页存储过程共有四种方式可以实现,行计数.游标.升序-降序.子查询 我记得曾经有人测试过这四种方式的效率分别是 从性能最好到最差的顺序进行的--行计数.游标.升序-降序.子查询 以下是我收集的一些资料供大家参考 QUOTE: 原文地址:http://www.codeproject.com/aspnet/PagingLarge.asp 作者:Jasmin Muharemovic  译者:Tony Qu 下载: 介绍 在Web应用程序中,对一个大数据库结果集进行分页已经是一个家喻户晓的问题了.简单的

超级ASP大分页_我的类容我做主

超级ASP大分页_我的类容我做主     选择自 AppleBBS 的 Blog   关键字   超级ASP大分页_我的类容我做主  出处    <%  '===================================================================  'ShowMorePage ASP版本  'Version HuangJM1.00  'Code by maomao  'Create Date 2004-09-28  'QQ:5144707  'http

ASP中存储过程调用的两种方式及比较

比较|存储过程|存储过程 beerfroth(原作) 本人用sql server 和asp写了一个简单的留言本,在不断的尝试中发现,分页显示留言的时候,不同的执行方式,时间上的一些差别. 下面通过对比来看看几种方式的用时对比. 一,使用存储过程分页,这种情况又分为两种方式: 第一种,使用command对象,如下: Set Cmd=server.CreateObject("Adodb.Command")Cmd.ActiveConnection=connCmd.CommandText=&q