#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    6
    Rep Power
    0

    Question How to Generate Pages - 1 | 2 | 3 etc...


    I've looked around for a good while trying to figure out how to do this... and I need your help.

    I have a web page that is dynamically generated and it display rows from a DB and the rows get to be in the 100s. I need to break it up into sections... but I'm not sure how to go about doing it.

    What I'm wanting is something like this:

    << Previous 1 | 2 | 3 | 4 Next >>

    (kindof like what is at the bottom of the forums here)

    Any insight, code, direction would greatly be apprectiated!

    --SureShot
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    5
    Rep Power
    0

    Re: How to Generate Pages - 1 | 2 | 3 etc...


    Originally posted by SureShot
    I've looked around for a good while trying to figure out how to do this... and I need your help.

    I have a web page that is dynamically generated and it display rows from a DB and the rows get to be in the 100s. I need to break it up into sections... but I'm not sure how to go about doing it.

    What I'm wanting is something like this:

    << Previous 1 | 2 | 3 | 4 Next >>

    (kindof like what is at the bottom of the forums here)

    Any insight, code, direction would greatly be apprectiated!

    --SureShot

    Try This:
    First, request a page number from the querystring.
    If Request.Querystring("Page") <> "" Then
    Page = CInt(Request.Querystring("Page"))
    Else
    Page = 1
    End If


    Open your recordset.
    RS.Open SqlQuery, DBConn, adOpenForwardOnly, adLockOptimistic

    Set your page size to the value of n. This sets how many records to display on one page.
    RS.PageSize = n

    Set a variable to get the page count.
    PageCount = RS.PageCount

    Check to see if PageCount is greater than 0. If true, we will set the recordset page to the page number from the querystring.
    If PageCount <> 0 Then
    RS.AbsolutePage = Page
    End If


    Next, just build your NEXT & PREVIOUS links in the HTML.
    <%
    If Page <> 1 Then
    %>
    <a href="filename.asp?Page=<%= Page - 1 %>">Previous Link</a>
    <%
    End If

    If Page < PageCount Then
    %>
    <a href="filename.asp?Page=<%= Page + 1 %>">Next Link</a>
    <%
    End If
    %>


    This generates Previous and Next links only.

    Regards,
    Matt
    Last edited by mwtall; March 5th, 2003 at 03:18 PM.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    6
    Rep Power
    0
    Matt, thank you very much... I will try this. The "NEXT and PREVIOUS" will be enough I think.

    Thanx a lot!
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    6
    Rep Power
    0
    Well, I'm getting errors with this code.

    I'm using a SQLOLEDB.... will that matter?
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Cincinnati, Ohio
    Posts
    25
    Rep Power
    0
    I doubt he meant for you to use his code literally. The key elements are in there, but you'll need to incorporate them into your existing code.

    Code:
    RS.PageSize = n
    PageCount = RS.PageCount
    RS.AbsolutePage = Page
    Where "RS" is the recordset object. Anyway, you should be able to integrate those items into your existing object and make it all work.

    dot
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    6
    Rep Power
    0

    Talking


    I didn't copy and paste his work literally... I did change all the variable and such to match my own and incorporated it into my code. I'm not a doof. ...but I guess you never can tell on the web.

    this is the error generated:
    Current Recordset does not support bookmarks. This may be a limitation of the provider or of the selected cursortype.

    that is why I asked if SQLOLEDB would work with this...
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    5
    Rep Power
    0
    When you are opening your recordset...

    Example:
    RS.Open SqlQuery, DBConnection

    What cursor are you using and what lock type? A static or forward-only cursor and an Optimistic lock should work and allow you to use Paging properties on the recordset.

    There shouldn't be anything wrong with using SQLOLEDB, as long as you're setting your recordset to a ADODB.Recordset object type.

    Use:
    RS.Open SqlQuery, DBConnection, adOpenStatic OR adOpenForwardOnly, adLockOptimistic

    If you don't have ADOVBS shortcuts....then use the values for the properties....

    adOpenStatic = 0
    adOpenForwardOnly = 1
    adLockOptimistic = 3

    Regards,
    Matt
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    6
    Rep Power
    0
    Well, I'm still getting the same error.

    I'll work on it and see if I can get it to work with what you all have said.

    Thanx y'all.
    Last edited by SureShot; March 7th, 2003 at 10:34 AM.
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    6
    Rep Power
    0

    Last straw!


    ------------------------------
    *****
    Got it... finally!
    thanx for everyones help
    *****
    Last edited by SureShot; March 12th, 2003 at 02:23 PM.

IMN logo majestic logo threadwatch logo seochat tools logo