Classic ASP Datagrid with Paging

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fary4u
    Contributor
    • Jul 2007
    • 273

    Classic ASP Datagrid with Paging

    Hi

    i've done the Datagrid view but only problem with displaying pages
    here is the code for Datagrid
    Code:
        <%
        Dim I, iPageSize
     
        iPageSize = 9 'Change pages
        Dim arrPhotoNames
        arrPhotoNames = Array("1", "2", "3", "4", _
                          "5", "6", "7", "8", _
                          "9", "10", "11", "12", _
                          "13", "14", "15", "16",_
                          "17", "18", "19", "20", _
                          "21", "22", "23", "24", "25")
     
        
        %><table border="1" ><tr><%
     
     For I = LBound(arrPhotoNames) To UBound(arrPhotoNames)
            
            %><td align="center"><%
            Response.Write arrPhotoNames(I)
            %></td><%
            ' change this number but next number is less then previouse 
            ' example 5 = 4 or 4 = 3 it's mod function
            If I Mod 3 = 2 Then
                    %></tr><tr><%
                End If
            
     Next 'I
        %>
    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
  • Fary4u
    Contributor
    • Jul 2007
    • 273

    #2
    any chance how to get around wd ths problme ?

    Comment

    • Fary4u
      Contributor
      • Jul 2007
      • 273

      #3
      i think so it's not possible am i rite ?

      Comment

      • jhardman
        Recognized Expert Specialist
        • Jan 2007
        • 3405

        #4
        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
        Code:
        <a href="samepage.asp?page=2">next 9 records</a>
        and right before I start reading the records I would put something like this:
        Code:
        dim firstRecord
        if request(page) <> "" then
           if cint(request(page)) > 1 then
              firstRecord = cint(request(page)) * 9 - 9
              objRS.move(firstRecord)
           end if
        end if
        
        for x = 0 to 8
           '...
        Does this make sense?

        Jared

        Comment

        • Fary4u
          Contributor
          • Jul 2007
          • 273

          #5
          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 ?

          Code:
          Error Type:
          Microsoft VBScript runtime (0x800A0009)
          Subscript out of range: '9'
          /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 : (

          Code:
          	iRecFirst   = (iPageCurrent-1)
          	iRecLast    = iRecFirst + iPageSize
          	iFieldFirst = LBound(arrPhotoNames, 1)
          	iFieldLast  = UBound(arrPhotoNames, 1)
          does it make any sense ? thanks for you reply.
          here is rest of the code.

          Code:
          	  arrPhotoNames.PageSize = iPageSize
          	  arrPhotoNames.CacheSize = iPageSize
          	  iPageCount = arrPhotoNames.PageCount
          
          	  	If iPageCurrent > iPageCount Then
          			 iPageCurrent = iPageCount
          		end if
          		If iPageCurrent < 1 Then
          			 iPageCurrent = 1
          		end if
          
          	If iPageCount = 0 Then
          		Response.Write "No Records found"
          	Else
          		arrPhotoNames.AbsolutePage = iPageCurrent
          		
          		iRecordsShown = 0
          	Do While iRecordsShown < iPageSize and not arrPhotoNames.EOF
          
          Executed Code ------------------------------------
          
                iRecordsShown = iRecordsShown 
          
          	Loop
          
          	End if
          
          If iPageCurrent > 1 Then
          %>
          <a HREF="getrow.asp?intCatalogID=<%= Server.URLEncode(strParam) %>&page=<%= iPageCurrent - 1 %>
          <%
          
          End If
          For I2 = 1 To iPageCount
          %>
          
          <a href="getrow.asp?intCatalogID=<%= Server.URLEncode(strParam) %>&page=<%= I2 %>| <%= I2 %> |</a>
          <%
          Next 'I2
          
          If iPageCurrent < iPageCount Then
          %>
          <a HREF="getrow.asp?intCatalogID=<%= Server.URLEncode(strParam) %>&page=<%= iPageCurrent + 1 %>
          
          <%
          End If
          %>

          Comment

          Working...