网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP技巧
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.升级到2003后访问数据库发生8007.
.使用速度更快的OLEDB取代ODBC连结.
.聊天室关键技术[用户断线]处理.
.ASP限制只能中文输入的方法.
.使用组件封装数据库操作(二).
.一段返回随机记录的代码.
.灵活实用的页面广告实例.
.不用java的垂直滚动看板.
.树型结构在ASP中的简单解决.
.用IIS+ASP建网站的安全性分析.
.页边距的设定技巧(HTML).
.新手学堂:rs.open与conn.execut.
.构建你的网站新闻自动发布系统之.
.开发连接远程SQL Server 的ASP程.
.ASP如何使用MYSQL数据库.
.提高ASP页面的执行效率(下).
.不刷新页面改变下拉菜单内容.
.如何在ASP中使用类.
.SQL注入技术和跨站脚本攻击的检测.
.ASP+JS处理复杂表单的生成与验证.

用RecordSet实现分页(by Daniel Adrian)

发表日期:2000-10-16


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!

上一篇:关于Global.asa文件的深入研究与session变量失效提示的具体方法 人气:14643
下一篇:从数据库中动态选取下拉列表的方法 人气:11857
浏览全部RecordSet的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐