当前位置: 首页 > 图文教程 > 网络编程 > ASP > 用RecordSet实现分页(by Daniel Adrian)

ASP
如何使用ASP产生象安装向导的主页
ADO如何取得数据库中表的字段信息之一
ADO如何取得数据库中表的字段信息之二
网页计数器的程序
实验Recordset.Movenext,Recordset.Previous,Recorset...等移动记录
不能ASP图像组件来生成图像的ASP计数器程序(一)
IIS5 + ADO 2.5新先睹为快技术(一)
IIS5 + ADO 2.5新先睹为快技术(二)
如何使用 Microsoft Access 和 Active Server Pages 加密你的页面
WINDOWS 2000搭載ASP3.0和IIS5.0
IIS 5.0新功能
网络开发之编程技巧之一(有效验证用户的登录)
如何使用ASP在自己的网站建立投票机制(一)
如何使用ASP在自己的网站建立投票机制(二)
组件对象开发Web应用的实例分析
如何实现动态添加Html文档中Form项
一个BBS的源代码(一)
一个BBS的源代码(二)
一个BBS的源代码(三)
一个BBS的源代码(四)

ASP 中的 用RecordSet实现分页(by Daniel Adrian)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 41 ::
收藏到网摘: n/a

  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!