On Paging, I am having a problem with the NEXT button

Results 1 to 7 of 7

Thread: On Paging, I am having a problem with the NEXT button

  1. #1
    Join Date
    Dec 1969
    Posts
    1,315

    Default On Paging, I am having a problem with the NEXT button

    Hello. I am trying to adapt the Paging example from this web site. It seems to work great but I am having a problem with the NEXT button. It seems to display the NEXT button even if there is only 1 page or if it is on the last page. I have looked it over for hours and I can not seem to find the answer. If anyone has any advise, I would be greatly appreciative. Thank you so much! My code is listed below. <BR><BR>-John (narsec@delphi.com)<BR><BR>&#060;%@ LANGUAGE="VBSCRIPT" &#037;&#062;<BR>&#060;% Option Explicit &#037;&#062;<BR>&#060;!-- #INCLUDE FILE="adovbs.inc" --><BR>&#060;%<BR>&#039Set how many records per page we want<BR>Const NumPerPage = 5<BR><BR>&#039Retrieve what page we&#039re currently on<BR>Dim CurPage<BR>If Request.QueryString("CurPage") = "" then<BR>CurPage = 1 &#039We&#039re on the first page<BR>Else<BR>CurPage = Request.QueryString("CurPage")<BR>End If<BR><BR>Dim conn<BR>Set conn = Server.CreateObject("ADODB.Connection")<BR>conn.Op en "DSN=Contact"<BR><BR>&#039Explicitly Create a recordset object<BR>Dim rs<BR>Set rs = Server.CreateObject("ADODB.Recordset")<BR><BR>&#03 9Set the cursor location property<BR>rs.CursorLocation = adUseClient<BR><BR>&#039Set the cache size = to the # of records/page<BR>rs.CacheSize = NumPerPage<BR><BR>&#039Open our recordset<BR>Dim strSQL<BR><BR>strSQL="SELECT * FROM datalist ORDER BY name ASC"<BR>rs.Open strSQL, Conn<BR><BR>rs.MoveFirst<BR>rs.PageSize = NumPerPage<BR><BR>&#039Get the max number of pages<BR>Dim TotalPages<BR>TotalPages = rs.PageCount<BR><BR>&#039Set the absolute page<BR>rs.AbsolutePage = CurPage<BR><BR>&#039Counting variable for our recordset<BR>Dim count<BR>&#037;&#062;<BR>&#060;html><BR><BR>&#060; head><BR>&#060;title>New Page &#060;/title><BR>&#060;/head><BR><BR>&#060;body><BR>&#060;b><BR><BR>&#060; p>Name - Salary&#060;/b><BR><BR>&#060;%<BR>&#039Set Count equal to zero<BR>Count = 0<BR>&#037;&#062;&#060;/p><BR><BR>&#060;table border="0" cellpadding="0" cellspacing="0" width="600"><BR> &#060;tr><BR> &#060;td nowrap align="center">&#060;/td><BR> &#060;td nowrap bgcolor="#008200" align="center">&#060;font face="Arial"<BR>color="#FFFFFF">&#060;small>&#060; small>&#060;strong>TERM&#060;/strong>&#060;/small>&#060;/small>&#060;/font>&#060;/<BR>td><BR> &#060;td nowrap bgcolor="#008200" align="center">&#060;font face="Arial"<BR>color="#FFFFFF">&#060;small>&#060; small>&#060;strong>ZIP&#060;/strong>&#060;/small>&#060;/small>&#060;/font>&#060;/t<BR>d><BR> &#060;td nowrap bgcolor="#008200" align="center">&#060;font face="Arial"<BR>color="#FFFFFF">&#060;small>&#060; small>&#060;strong>NAME<BR> / STATE&#060;/strong>&#060;/small>&#060;/small>&#060;/font>&#060;/td><BR> &#060;td nowrap bgcolor="#008200" align="center">&#060;font face="Arial"<BR>color="#FFFFFF">&#060;small>&#060; small>&#060;strong>DATE1&#060;/strong>&#060;/small>&#060;/small>&#060;/font>&#060;<BR>/td><BR> &#060;td nowrap bgcolor="#008200" align="center">&#060;font face="Arial"<BR>color="#FFFFFF">&#060;small>&#060; small>&#060;strong>DATE2&#060;/strong>&#060;/small>&#060;/small>&#060;/font>&#060;<BR>/td><BR> &#060;td nowrap bgcolor="#008200" align="center">&#060;font face="Arial"<BR>color="#FFFFFF">&#060;small>&#060; small>&#060;strong>DATE3&#060;/strong>&#060;/small>&#060;/small>&#060;/font>&#060;<BR>/td><BR> &#060;td nowrap bgcolor="#008200" align="center">&#060;font face="Arial"<BR>color="#FFFFFF">&#060;small>&#060; small>&#060;strong>DATE4&#060;/strong>&#060;/small>&#060;/small>&#060;/font>&#060;<BR>/td><BR> &#060;td nowrap bgcolor="#008200" align="center">&#060;font face="Arial"<BR>color="#FFFFFF">&#060;small>&#060; small>&#060;strong>NOTES&#060;/strong>&#060;/small>&#060;/small>&#060;/font>&#060;<BR>/td><BR> &#060;/tr><BR>&#060;%<BR>Do While Not rs.EOF And Count &#060; rs.PageSize<BR>&#037;&#062;<BR> &#060;tr><BR> &#060;td>&#060;/td><BR> &#060;td style="border-bottom: 1px solid rgb(0,130,0)">&#060;p<BR>align="center">&#060;font face="Arial"<BR><BR>color="#400040">&#060;strong>& #060;small>&#060;small>&#060;%=RS("1")&#037;&#062; &#060;/small>&#060;/small>&#060;/strong>&#060;<BR>/font>&#060;/td><BR> &#060;td style="border-bottom: 1px solid rgb(0,130,0)">&#060;p<BR>align="center">&#060;smal l>&#060;font<BR> face="Arial">&#060;%response.write<BR>Formatnumber (RS("2"),3)&#037;&#062;&#060;/font>&#060;/small>&#060;/td><BR> &#060;td style="border-bottom: 1px solid rgb(0,130,0)">&#060;p<BR>align="center">&#060;stro ng>&#060;small>&#060;small>&#060;a<BR> target="_self" style="color: rgb(0,119,0); font-weight: bolder"<BR> href="callable_detail.asp?Param2=&#060;%=RS("A")&# 037;&#062;">&#060;font face="Arial"<BR>color="#007700">&#060;%=RS("3")&#0 37;&#062;&#060;/font>&#060;/a>&#060;font<BR> face="Arial" color="#007700">, &#060;/font>&#060;a target="_self"<BR> style="color: rgb(0,119,0); font-weight: bolder"<BR> href="callable_detail.asp?Param2=&#060;%=RS("4")&# 037;&#062;">&#060;font face="Arial"<BR>color="#007700">&#060;%=RS("b")&#0 37;&#062;&#060;/font>&#060;/a>&#060;/small>&#060;/small>&#060;/strong>&#060;/td><BR> &#060;td style="border-bottom: 1px solid rgb(0,130,0)">&#060;p<BR>align="center">&#060;font face="Arial"<BR><BR>color="#400040">&#060;strong>& #060;small>&#060;small>&#060;%=RS("5")&#037;&#062; &#060;/small>&#060;/small>&#060;/strong>&#060;<BR>/font>&#060;/td><BR> &#060;td style="border-bottom: 1px solid rgb(0,130,0)">&#060;p<BR>align="center">&#060;font face="Arial"<BR><BR>color="#400040">&#060;strong>& #060;small>&#060;small>&#060;%=RS("6")&#037;&#062; &#060;/small>&#060;/small>&#060;/strong>&#060;<BR>/font>&#060;/td><BR> &#060;td style="border-bottom: 1px solid rgb(0,130,0)">&#060;p<BR>align="center">&#060;font face="Arial"<BR><BR>color="#400040">&#060;strong>& #060;small>&#060;small>&#060;%=RS("7")&#037;&#062; &#060;/small>&#060;/small>&#060;/strong>&#060;<BR>/font>&#060;/td><BR> &#060;td style="border-bottom: 1px solid rgb(0,130,0)">&#060;font face="Arial"<BR>color="#400040">&#060;strong>&#060 ;small>&#060;small>&#060;%=RS("8")&#037;&#062;&#06 0;/small>&#060;/small>&#060;/strong>&#060;<BR>/font>&#060;/td><BR> &#060;td style="border-bottom: 1px solid rgb(0,130,0)">&#060;font face="Arial"<BR>color="#400040">&#060;strong>&#060 ;small>&#060;small>&#060;%=RS("9")&#037;&#062;&#06 0;/small>&#060;/small>&#060;/strong>&#060;<BR>/font>&#060;/td><BR> &#060;/tr><BR>&#060;%<BR><BR>Count = Count + 1<BR>rs.MoveNext<BR>Loop<BR>&#037;&#062;<BR>&#060 ;/table><BR>&#060;%<BR>&#039Print out the current page # / total pages<BR>Response.Write("Page " & CurPage & " of " & TotalPages & "&#060;P>")<BR><BR>&#039Display Next / Prev buttons<BR>if CurPage > 1 then<BR>&#039We are not at the beginning, show the prev button<BR>Response.Write("&#060;INPUT TYPE=BUTTON VALUE=PREV<BR>ONCLICK=""document.location.href=&#0 39thisfile.asp?curpage=" & curpage - 1 &<BR>"&#039;"">")<BR>End If<BR><BR>if CurPage &#060;> TotalPages then<BR>&#039We are not at the end, show a next button<BR>Response.Write("&#060;INPUT TYPE=BUTTON VALUE=NEXT<BR>ONCLICK=""document.location.href=&#0 39thisfile.asp?curpage=" & curpage + 1 &<BR>"&#039;"">")<BR>End If<BR><BR>&#037;&#062;<BR>&#060;/body><BR>&#060;/html><BR><BR><BR><BR><BR><BR>

  2. #2
    Join Date
    Dec 1969
    Posts
    552

    Default RE: On Paging, I am having a problem with the NEXT button

    Try changing the if statement:<BR><BR>if CurPage &#060;> TotalPages then<BR>&#039We are not at the end, show a next button<BR>Response.Write("&#060;INPUT TYPE=BUTTON VALUE=NEXT<BR>ONCLICK=""document.location.href=&#0 39thisfile.asp?curpage=" & curpage + 1 &<BR>"&#039"">")<BR>End If<BR><BR><BR>to<BR><BR>if CurPage &#060;> TotalPages-1 then<BR>&#039We are not at the end, show a next button<BR>Response.Write("&#060;INPUT TYPE=BUTTON VALUE=NEXT<BR>ONCLICK=""document.location.href=&#0 39thisfile.asp?curpage=" & curpage + 1 &<BR>"&#039"">")<BR>End If<BR><BR>(Note the "- 1")<BR><BR>Basically, I&#039d recommend you always have CurPage and TotalPages printed out on the screen while you&#039re still debugging. That way you can see what values they hold when the last page is being shown, and you can alter your conditional statement as needed.

  3. #3
    Join Date
    Dec 1969
    Posts
    1,315

    Default RE: On Paging, I am having a problem with the NEXT button

    Thank you for your responce. I tried the -1 and unfortunately it didn&#039t work. I placed the following statments above the last if statement:<BR><BR>Response.Write("Current Page " & CurPage & "&#060;P>")<BR>Response.Write("Total Pages " & TotalPages & "&#060;P>")<BR><BR>I then made it so there are only 3 records in the database and changed the line to ----> Const NumPerPage = 2<BR><BR>With NO -1 it shows:(Original)<BR>Current Page 1, Total Pages 2 On Page 1 and a next button<BR>Current Page 2, Total Pages 2 On Page 2 and both buttons<BR><BR>With a -1 it shows:<BR>Current Page 1, Total Pages 2 On Page 1 and a next button<BR>Current Page 2, Total Pages 2 On Page 2 and both buttons<BR>The Same<BR><BR>I made sure that I refreshed the pages when I went to them in the browser. <BR><BR>Maybe another idea?<BR><BR>Thanks again.<BR>-John (narsec@delphi.com)<BR> <BR><BR><BR>

  4. #4
    Join Date
    Dec 1969
    Posts
    1,315

    Default RE: On Paging, I am having a problem with the NEXT button

    Yeah, I&#039ve got another idea. Try explicitly forcing the variables to be ints.<BR><BR>If CInt(CurPage) = CInt(TotalPages)<BR><BR>or whatever the if statement looks like... just use CInt(variableName) around both CurPage and TotalPages. Does that work for you now?


  5. #5
    Join Date
    Dec 1969
    Posts
    552

    Default RE: On Paging, I am having a problem with the NEXT button

    Did the CInt approach work?

  6. #6
    Join Date
    Dec 1969
    Posts
    1,315

    Default RE: On Paging, I am having a problem with the NEXT button

    It sure did. Thanks

  7. #7
    Join Date
    Dec 1969
    Posts
    2,849

    Default RE: On Paging, I am having a problem with the NEXT button

    Just stumbled across this thread, didn&#039t realize there was an error on the paging example. I will fix it, thanks for the heads up, Tim/John! Have a great day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •