您现在的位置: 军旅同心-旅游自驾-军旅文学 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 正文
用RecordSet实现分页(by Daniel Adrian)
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 14:19:47
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!


更多
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 网站地图 | 版权申明 | 网站公告 | 管理登录 |