Print Page | Close Window

Recordset paging

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=12807
Printed Date: 30 March 2026 at 9:21pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Recordset paging
Posted By: Mattblack
Subject: Recordset paging
Date Posted: 02 December 2004 at 5:47pm
boo, back again!
 
Im struggling to use paging for a recordset, never done it before so i went to w3schools and following it all to the letter - no joy!
 
open the recordset
rs.pagesize=5
 
this shows ALL records not just the first page. Do I have to set the page its on? How do i do it anyhow for page 2?
 
Also, rs.pagecount writes "-1" when it should be about 4 pages.
 
Totally confused, ive followed it to the letter.  Have also tried with different locktypes.
 
Pleeeeeeeeeeeeease help
 



Replies:
Posted By: rx7tt
Date Posted: 02 December 2004 at 9:05pm

I will trim down some code and post it shortly.



Posted By: rx7tt
Date Posted: 02 December 2004 at 9:56pm

The code is pretty bland but I wanter to make sure it was understandable. Please let me know if you have any questions.

Thanks
 
<%
Set sqlConn = SERVER.CREATEOBJECT("ADODB.CONNECTION")
SET RS = SERVER.CREATEOBJECT("ADODB.RECORDSET")

' This will tell the recordset what page your on
Page = Request.QueryString("page")' Declare page number
If Page = "" Then
  iPageCurrent = CInt(1)'If there is no page then page is 1
Else
  iPageCurrent = CInt(Page)
End If

'Set the cursor type property of the record set to dynamic so we can naviagate through the record set
rs.CursorType = 1

'----------------------------------------------------------- ------
' Open your connection and recordset here
'----------------------------------------------------------- ------

'This will tell the recordset how many records to return
iPageSize = 10

'Get the total number of records in the recordset
iTotalRecords = RS.RecordCount ' Total # of records

'Define max number of records
RS.PageSize = iPageSize

'Get the total number of page in the recordset
iPageCount = RS.PageCount ' Total # of pages

'Move to the current page in the recordset
RS.AbsolutePage = iPageCurrent

'Counter to keep track of the number of records displayed
iRecordsShown = 0

'Loop thru records until Page Size is reached
Do While iRecordsShown < iPageSize AND Not RS.EOF

  '----------------------------------------------------------- ------
  ' Output you recorset
  ' eg Response.Write RS("Record1")
  '----------------------------------------------------------- ------

  'increment counter
  RS.MoveNext
  iRecordsShown = iRecordsShown + 1
Loop

If iPageCurrent > 1 Then
  Response.Write "<a href=""test.asp?page=" & iPageCurrent - 1 & """>Previous " & iPageSize & "</a>" & vbCrLf
End If

'Display a next link if needed
If iPageCount <> iPageCurrent Then
  Response.Write "<a href=""test.asp?page=" & iPageCurrent + 1 & """>Next " & iPageSize & "</a>" & vbCrLf
End If

'Clean up
RS.Close
Set RS = Nothing
sqlConn.Close
Set sqlConn = Nothing
%>



Posted By: Mattblack
Date Posted: 03 December 2004 at 7:41am
excellent, ive got it working.
 
I missed out the cursor location with the type.
 
Thanks mate


Posted By: rx7tt
Date Posted: 05 December 2004 at 8:27pm

Glad to help Smile



-------------
http://www.mobilegear.biz - Mobile Gear.biz -Ringtones, games, videos, links and more...
http://www.mobilegear.biz/forum/ - Wireless Forums



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net