Implementing pagination with a Recordset (by Daniel Adrian)

Source: Internet
Author: User
Paging through a recordset
by Daniel Adrian

Skill Level:beginner

Posted:monday, October 09, 2000





Paging through a recordset

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

This can is done very easily. Shall we start?

Take a look at this 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") are 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 to have records because is 20.

Now let's pull out some records:

Do until objRS. Eof
If n = Recordstoshow Then
Exit Do
End If
Write what that your 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 do
It some when it's we'll 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



The are checking if the current page isn't 1 so it's more then one so we can go back.

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

That is all! Yes it ' s that easy!


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.