I’m having some trouble with my asp paging. It’s able to show the 6 records on each page. However, when i move on to the second page, it’s showing the same 6 records on every different page.
Below is my code. Any suggestions?
Dim iPageSize,iPageCount , iPageCurrent , strOrderBy,strSQL,iRecordsShown,I
iPageSize = 6
set registerRS=server.CreateObject("ADODB.recordset")
registerRS.PageSize = iPageSize
' Retrieve page to show or default to 1
If Request.QueryString("page") = "" Then
iPageCurrent = 1
Else
iPageCurrent = CInt(Request.QueryString("page"))
End If
qry="SELECT * FROM "dbo.CustomerOrders;"
registerRS.CacheSize = iPageSize
registerRS.open qry,ObjConn,3
iPageCount = registerRS.PageCount
If iPageCurrent > iPageCount Then iPageCurrent = iPageCount
If iPageCurrent < 1 Then iPageCurrent = 1
If iPageCount = 0 Then
Response.Write "No records found!"
Else
registerRS.AbsolutePage = iPageCurrent
end if
%>
<p>
<font size="+1">Page <strong><%= iPageCurrent %></strong>
of <strong><%= iPageCount %></strong></font>
</p>
<%
x=registerRS.recordcount
if registerRS.recordcount > 0 Then
registerRS.movefirst
End If
Do While iRecordsShown < iPageSize And Not registerRS.EOF
counter=counter+1
if counter=41 then
counter=0
counter=counter+1
end if
r = r + 1
If r = 1 then
Response.write "<tr>"
End if
%>
<td>
<%=registerRS.Fields("Address")%> <br />>
</td>
<%
If r = 2 then
Response.write "</tr>"
End if
If r = 3 then r = 1
' Increment the number of records we've shown
iRecordsShown = iRecordsShown + 1
registerRS.movenext
loop
%>
</table>
<table width=90%>
<tr>
<td>
<%
If iPageCurrent > 1 Then
%>
<a href="add.asp?page=<%= iPageCurrent - 1 %>&SchoolId=<%=registerRS.Fields("Add")%>">[<< Prev]</a>
<%
End If
' You can also show page numbers:
For I = 1 To iPageCount
If I = iPageCurrent Then
%>
<%= I %>
<%Else%>
<a href="add.asp?page=<%= I %>&SchoolId=<%=registerRS.Fields("Add")%>"><%= I %></a>
<%
End If
Next 'I
If iPageCurrent < iPageCount Then
%>
<a href="add.asp?page=<%= iPageCurrent + 1 %>&SchoolId=<%=registerRS.Fields("Add")%>">[Next >>]</a>
<%
registerRS.close
set registerRS=nothing
End If
end sub
%>
Do a view source on the web page and verify that this line of code:
is producing the correct result. If not then you will need to backtrack to find out where the correct page reference is not being generated.
Compare your code to this example for possible error sources.
http://www.asp101.com/samples/viewasp.asp?file=db_paging.asp
I did some testing and I see a couple of things that may be causing problems.
1] You need to initialize iRecordsShown = 0 before the Do-Loop.
2] You are also trying to retrieve database values into you links after the loop. This won’t likely work because the loop has already reached the end of records by that time. You’ll need to capture the database values before the end of loop is reached.
Otherwise it worked for me.