473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Paging Problem in ASP

Hi all, I have a problem with my paging script. The first time it executes, (say it gives 5 pages of records), it will display 1 of 5 but when i click on the next button, it gives 1 of 1 . Please can someone help.
Expand|Select|Wrap|Line Numbers
  1.     pagenum            = Session("pagenum")
  2.     pagecnt            = Session("pagecnt")
  3.  
  4. Call displayRecords()
  5.  
  6. +++++++++++++++
  7.  
  8. Sub displayRecords()
  9.         ' SET NUMBER OF records TO DISPLAY PER PAGE
  10.         PerPage = 10
  11.  
  12.         rsSelect = "Select aID, Name, price FROM tblA"
  13.         Set rsHCheck = Server.CreateObject("ADODB.RecordSet")
  14.         rsH.PageSize = PerPage
  15.         rsH.CursorLocation = 3
  16.         rsH.Open rsSelect, oConn
  17.  
  18.  
  19.        ' session("pagecnt") = pagecnt
  20.         Response.Write "pagenum: " & pagenum & "<br />"
  21.         Response.Write "pagecnt: " & pagecnt & "<br />"
  22.  
  23.  
  24.  
  25.         If rsH.EOF Then
  26.                pagecnt = rsH.pageCount
  27.             Response.Write "pagecnt if EOF: " & pagecnt & "<br />"
  28.             Call displayPaging(pagenum, pagecnt)
  29.             Call displayBoardTypes()
  30.  
  31.                 Response.Write("<p style='margin-left: 30px;'>We could not find any records matching your search criteria.</p>")
  32.  
  33.         Else
  34.             rsH.AbsolutePage = pagenum
  35.             pagecnt = rsH.pageCount
  36.             Response.Write "pagecnt if not eof: " & pagecnt & "<br />"
  37.  
  38.             Call displayPaging(pagenum, pagecnt)
  39.  
  40.  
  41.             For k = 1 To PerPage
  42.                 If Not rsH.EOF Then
  43.                     response.write" blah blah" 
  44.  
  45.                     End Select
  46.  
  47.                 rsH.MoveNext
  48.                End If
  49.            Next
  50.  
  51.         Response.Write "pagecnt if not eof: " & pagecnt & "<br />"
  52.  
  53.  
  54.         Call displayPaging(pagenum, pagecnt)
  55.  
  56.         End If
  57.         pagecnt = rsH.pageCount
  58.         Response.Write "pagecnt: " & pagecnt & "<br />"
  59.  
  60.         Set rsH = Nothing
  61. End Sub
  62. +++++++++++++++++++++++++++++++++++++++++
  63.  
  64.  
  65. Sub displayPaging(pagenum, pagecnt)
  66.         ' SET PREVIOUS PAGE
  67.         prevPage = "&laquo; Prev page&nbsp;&nbsp;"
  68.         If pagenum >= 2 Then prevPage = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=""javascript:showRecords(" " & pagenum - 1 & ", " & pagecnt & ")"" >&laquo; Prev page&nbsp;&nbsp;</a>"
  69.  
  70.  
  71.         ' SET NEXT PAGE
  72.         Response.Write ("    pagecnt:   "& Trim( pagecnt ) & "</br />" & vbcrlf)
  73.         nextPage = "&nbsp;&nbsp;Next page &raquo;"
  74.         If Trim( pagenum ) <> Trim( pagecnt ) Then nextPage = "&nbsp;&nbsp;<a href=""javascript:showHotels(" & pagenum + 1 & " , " & pagecnt & ")"">Next page &raquo;</a>"
  75.  
  76.         Response.Write ("<div class='paging'>" & vbcrlf)
  77.         Response.Write ("    <div class='middle'>Displaying page <strong>"& pagenum & "</strong> of <strong>" & pagecnt & "</strong></div>" & vbcrlf)
  78.         Response.Write ("    <div class='prev'>"& prevPage & "</div>" & vbcrlf)
  79.         Response.Write ("    <div class='next'>"& nextPage & "</div>" & vbcrlf)
  80.  
  81.     End Sub
  82.  
++++++++++++++++++++++++++++++++++++++++++++
Oct 5 '07 #1
2 1661
If you simply wish to display several records on a page at a time and have paging, then let ASP.NET controls do the work for you!

Say,
  1. create a SqlDataSource control, set it's connection to which ever connection is in your web.config file.
    Next, choose either the table and fields you wish to bind to or use a stored procedure.
    Once your able to establish a connection to your data, simply use a control such as a "FormsView" control. Enable paging, set the page size limit, set it's datasource to the sqldatasource you created and wah lah! Or you may use the GridView control as well. I prefer the FormsView because you can customize your appearance and layout more easily, such as displaying in tables and such.

A possible cause of such problem is keeping track of variables on the page, and often times, when the page is refreshed, variables are lost therefore losing the sync between pages and your pager control.

Hope this helps.
Oct 5 '07 #2
jhardman
3,406 Expert 2GB
it looks like the pagecount is saved as a sessioni-level variable, which is generally a pretty safe way to save it. I noticed though that line 19 which appears to save this data is commented out. I don't see any other line where this data is affected. Perhaps uncommenting this line would sove this problem, however I admit that I didn't read through the code very thoroughly.

Jared
Oct 8 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: asad | last post by:
Hello friends, i am designing a ASP.NET page where i want to use custom paging bcoz data is too heavy so pls tell me how can i use custom paging in ASP.NET Thanks
2
by: farhad13841384 | last post by:
Hi , I Hope You fine. I have some problem with this code for paging in asp.net this bottom code work correctly without any error but when I try to place separate code in .VB file then error is...
0
by: anonieko | last post by:
This approach I found very efficient and FAST when compared to the rowcount, or Subquery Approaches. This is before the advent of a ranking function from DB such as ROW_NUMBER() in SQL Server...
2
by: rn5a | last post by:
In a shopping cart app, a ASPX page retrieves the order details & personal details of a user from a MS-Access database table depending upon the username of the user. The order details of a...
5
by: Donald Adams | last post by:
Hi, I will have both web and win clients and would like to page my data. I could not find out how the datagrid control does it's paging though I did find some sample code that says they do it...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.