<%@ LANGUAGE="VBSCRIPT" %> <% ' Listing 17.1 Paging through a Recordset Part 1: Declaration Option Explicit Response.Expires = 5 %> <% Const intPageSize = 5 Dim intCurrentPage, objConn, objRS, strQ Dim intTotalPages, intI ' Listing 17.2 Paging Part 2: Setting the Current Page Number If Request.ServerVariables("CONTENT_LENGTH") = 0 Then intCurrentPage = 1 Else intCurrentPage = CInt(Request.Form("CurrentPage")) Select Case Request.Form("Submit") Case "Previous" intCurrentPage = intCurrentPage - 1 Case "Next" intCurrentPage = intCurrentPage + 1 End Select End If ' Listing 17.3[em]Paging[md]Part 3: Preparing the Recordset for Paging Set objRS = Server.CreateObject("ADODB.Recordset") objRS.CursorLocation = adUseClient objRS.CursorType = adOpenStatic objRS.CacheSize = intPageSize ' Listing 17.4[em]Paging[md]Part 4: Opening the Recordset strQ = "SELECT * " strQ = strQ & "FROM Products ORDER BY ProductID DESC" objRS.Open strQ, objConn, adOpenForwardOnly, adLockReadOnly, adCmdText ' Listing 17.5 Paging Part 5: Setting the Recordset cursor objRS.PageSize = intPageSize If Not(objRS.EOF) Then objRS.AbsolutePage = intCurrentPage ' Listing 17.6 Paging Part 6: Sending Database Data intTotalPages = objRS.PageCount %> St Andrews of Course Golf Trade Site

Products

<% For intI = 1 to objRS.PageSize Response.Write "

" &_ "" Response.Write "
" & objRS("ProductID") & "
" &_ "

" & objRS("ProductName") & "

" &_ "" & objRS("ProductDesc") & "


" objRS.MoveNext If objRS.EOF Then Exit For Next Set objRS = Nothing : Set objConn = Nothing %>
Page <%= intCurrentPage %> of <%= intTotalPages %>

<% ' Listing 17.7 Paging Part 7: Providing Web Form for Paging %>
" METHOD="POST"> <% If intCurrentPage > 1 Then %> <% End If If intCurrentPage <> intTotalPages Then %> <% End If %>
Home
about us
products
LOG ON
Register