Connecting Tech Pros Worldwide Forums | Help | Site Map

Classic ASP Datagrid with Paging

Familiar Sight
 
Join Date: Jul 2007
Location: United Kingdom
Posts: 203
#1: Sep 1 '09
Hi

i've done the Datagrid view but only problem with displaying pages
here is the code for Datagrid
Expand|Select|Wrap|Line Numbers
  1.     <%
  2.     Dim I, iPageSize
  3.  
  4.     iPageSize = 9 'Change pages
  5.     Dim arrPhotoNames
  6.     arrPhotoNames = Array("1", "2", "3", "4", _
  7.                       "5", "6", "7", "8", _
  8.                       "9", "10", "11", "12", _
  9.                       "13", "14", "15", "16",_
  10.                       "17", "18", "19", "20", _
  11.                       "21", "22", "23", "24", "25")
  12.  
  13.  
  14.     %><table border="1" ><tr><%
  15.  
  16.  For I = LBound(arrPhotoNames) To UBound(arrPhotoNames)
  17.  
  18.         %><td align="center"><%
  19.         Response.Write arrPhotoNames(I)
  20.         %></td><%
  21.         ' change this number but next number is less then previouse 
  22.         ' example 5 = 4 or 4 = 3 it's mod function
  23.         If I Mod 3 = 2 Then
  24.                 %></tr><tr><%
  25.             End If
  26.  
  27.  Next 'I
  28.     %>
  29.  
what i would like to do now showing paging for display
1st 9 records on 1st page ( 1,2,3,4,5,6,7,8,9 )
2nd 9 records on 2nd page ( 10,11,12,13,14,15,16,17,18 )
3rd 9 records on 3rd page ( 19,20,21,22,23,24,25 ) & rest

this page will be automatically
important thing with this code is you can change the row & col with MOD Method

how can we show the paging ?
any body knows how to fix this code ?

thanks 4 reply & regards
Fary

Familiar Sight
 
Join Date: Jul 2007
Location: United Kingdom
Posts: 203
#2: Sep 2 '09

re: Classic ASP Datagrid with Paging


any chance how to get around wd ths problme ?
Familiar Sight
 
Join Date: Jul 2007
Location: United Kingdom
Posts: 203
#3: Sep 4 '09

re: Classic ASP Datagrid with Paging


i think so it's not possible am i rite ?
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#4: Sep 6 '09

re: Classic ASP Datagrid with Paging


it's possible, there's just no built-in way to do it. To show a certain number of records on a page you would need to use "for x = 0 to 8" to loop through the records instead of the common method of "do until objRS.eof", but then you would need to clarify that if the end of the records are reached you need to exit the loop: "if objRS.eof then exit for".

To open a record list in the middle, use the objRS.move() command. For example, I might put a link with something like
Expand|Select|Wrap|Line Numbers
  1. <a href="samepage.asp?page=2">next 9 records</a>
and right before I start reading the records I would put something like this:
Expand|Select|Wrap|Line Numbers
  1. dim firstRecord
  2. if request(page) <> "" then
  3.    if cint(request(page)) > 1 then
  4.       firstRecord = cint(request(page)) * 9 - 9
  5.       objRS.move(firstRecord)
  6.    end if
  7. end if
  8.  
  9. for x = 0 to 8
  10.    '...
Does this make sense?

Jared
Familiar Sight
 
Join Date: Jul 2007
Location: United Kingdom
Posts: 203
#5: Sep 7 '09

re: Classic ASP Datagrid with Paging


Hi Jared

your 100% rite coz i've done the coding but slightly different way but now only problem with last page & it's giving me error ?

Expand|Select|Wrap|Line Numbers
  1. Error Type:
  2. Microsoft VBScript runtime (0x800A0009)
  3. Subscript out of range: '9'
  4. /desktop/asp download/getrow.asp, line ( problem is in this code ) 
but i find another problem which is very rare ? & makes me confused ?
when it's shows 9 records it's takes 1 extra vaule : (

Expand|Select|Wrap|Line Numbers
  1.     iRecFirst   = (iPageCurrent-1)
  2.     iRecLast    = iRecFirst + iPageSize
  3.     iFieldFirst = LBound(arrPhotoNames, 1)
  4.     iFieldLast  = UBound(arrPhotoNames, 1)
  5.  
does it make any sense ? thanks for you reply.
here is rest of the code.

Expand|Select|Wrap|Line Numbers
  1.  
  2.       arrPhotoNames.PageSize = iPageSize
  3.       arrPhotoNames.CacheSize = iPageSize
  4.       iPageCount = arrPhotoNames.PageCount
  5.  
  6.           If iPageCurrent > iPageCount Then
  7.              iPageCurrent = iPageCount
  8.         end if
  9.         If iPageCurrent < 1 Then
  10.              iPageCurrent = 1
  11.         end if
  12.  
  13.     If iPageCount = 0 Then
  14.         Response.Write "No Records found"
  15.     Else
  16.         arrPhotoNames.AbsolutePage = iPageCurrent
  17.  
  18.         iRecordsShown = 0
  19.     Do While iRecordsShown < iPageSize and not arrPhotoNames.EOF
  20.  
  21. Executed Code ------------------------------------
  22.  
  23.       iRecordsShown = iRecordsShown 
  24.  
  25.     Loop
  26.  
  27.     End if
  28.  
  29. If iPageCurrent > 1 Then
  30. %>
  31. <a HREF="getrow.asp?intCatalogID=<%= Server.URLEncode(strParam) %>&page=<%= iPageCurrent - 1 %>
  32. <%
  33.  
  34. End If
  35. For I2 = 1 To iPageCount
  36. %>
  37.  
  38. <a href="getrow.asp?intCatalogID=<%= Server.URLEncode(strParam) %>&page=<%= I2 %>| <%= I2 %> |</a>
  39. <%
  40. Next 'I2
  41.  
  42. If iPageCurrent < iPageCount Then
  43. %>
  44. <a HREF="getrow.asp?intCatalogID=<%= Server.URLEncode(strParam) %>&page=<%= iPageCurrent + 1 %>
  45.  
  46. <%
  47. End If
  48. %>
  49.  
Reply