Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Posts
    122
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Paging & GetRows

    Folkz, i'm using the below code to do paging. It works, but I would like to expand it so that there is a First Button, Last Button, Next and Previous...

    Plus, if i am say on page 15, it would look like this
    12 13 14 15 16 17 18 19

    Any ideas?

    Code:
     Dim objConn, objRS, strSQL 
      
      set objConn=Server.CreateObject("ADODB.Connection")
      objConn.Provider="Microsoft.Jet.OLEDB.4.0"
      objConn.Open Server.MapPath("../Access/Units.mdb")
    
    	strSQL = "SELECT UnitsID "
    	strSQL =strSQL & " FROM Units"
    	'strSQL =strSQL & " tblDesc.DescID = tblGlossary.DescId) INNER JOIN "			
    	'strSQL =strSQL & " tblTerms ON tblGlossary.TermsId = tblTerms.TermsID;"  
    
    
      Set objRS = Server.CreateObject("ADODB.Recordset")
      objRS.Open strSQL, objConn
    
      Dim aResults
      aResults = objRS.GetRows
    
      objRS.Close
      Set objRS = Nothing
    
      objConn.Close
      Set objConn = Nothing
    
    
     '<------------- Paging
      Dim iStart, iOffset
      iStart = Request("Start")
      iOffset = Request("Offset")
    
      if Not IsNumeric(iStart) or Len(iStart) = 0 then
        iStart = 0
      else
        iStart = CInt(iStart)
      end if
    
      if Not IsNumeric(iOffset) or Len(iOffset) = 0 then
        iOffset = 10
      else
        iOffset = Cint(iOffset)
      end if
       
      Dim iRows, iCols, iRowLoop, iColLoop, iStop
      iRows = UBound(aResults, 2)
      iCols = UBound(aResults, 1)
    
      If iRows > (iOffset + iStart) Then
        iStop = iOffset + iStart - 1
      Else
        iStop = iRows
      End If
    
      For iRowLoop = iStart to iStop
        For iColLoop = 0 to iCols
          Response.Write aResults(iColLoop, iRowLoop) & " "
        Next
        Response.Write "<BR>"
      Next  
    
      Response.Write "<P>"
      if iStart > 0 then
        'Show Prev link
        Response.Write "<A HREF=""PagingAndGetRows.asp?Start=" & iStart-iOffset & _
                       "&Offset=" & iOffset & """>Previous " & iOffset & "</A>"
      end if
    
      if iStop < iRows then
        'Show Next link
        Response.Write " <A HREF=""PagingAndGetRows.asp?Start=" & iStart+iOffset & _
                       "&Offset=" & iOffset & """>Next " & iOffset & "</A>"
      end if

  • #2
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is an example based on the ASP101 sample
    http://computer-helpforum.com/asp/AD...age=1&order=id

    It has links for next/previous record and for next/previous 5 records.
    It also has first/last links.
    If there are appropriate records then the current record will be in the middle off the list with the next/previous 2 records linked.


  •  

    Posting Permissions

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