' Declare variables Dim iPageSize 'How big our pages are Dim strPageCount 'The number of pages we get back Dim strPageCurrent 'The page we want to show Dim strSql 'SQL select to limit fields Dim conn 'The connection object Dim rs 'The recordset object Dim x 'Standard looping var
If request("d1") <> "" Then Session("d1") = request("d1")
'Get parameters from the dropdown box on the previous page. ' You could easily just use the default of 10 iPageSize = Session("d1") If Request("page") = "" Then strPageCurrent = 1 Else strPageCurrent = CInt(Request("page")) End If
'Create db connection and recordset objects 'Open the connection string Set conn = Server.CreateObject("ADODB.Connection") Set rs = Server.CreateObject("ADODB.Recordset") conn.Open ConnString
' Set cursor location and pagesize rs.CursorLocation = adUseClient rs.PageSize = iPageSize
'set sql statement to a local variable strSql = "SELECT * FROM table1 ORDER BY id;"
' Open Recordset object rs.Open strSql, conn, adOpenStatic, adLockReadOnly, adCmdText
' Get the count of the pages using the given page size strPageCount = rs.PageCount
' If the request page falls outside the range, ' give them the closest match (1 or max) If 1 > strPageCurrent Then strPageCurrent = 1 If strPageCurrent > strPageCount Then strPageCurrent = strPageCount
' Move to the selected page rs.AbsolutePage = strPageCurrent
' Start output with a page x of n line Response.Write "<FONT SIZE=""+1"">Page <B>" Response.Write strPageCurrent Response.Write "</B> of <B>" Response.Write strPageCount Response.Write "</B></FONT><BR><BR>" & vbCrLf
' Continue with a title row in our table Response.Write "<TABLE BORDER=""1"">" & vbCrLf
' Show field names Response.Write vbTab & "<TR>" & vbCrLf For x = 1 To rs.Fields.Count Response.Write vbTab & vbTab & "<TD><B>" Response.Write rs.Fields(x - 1).Name Response.Write "<B></TD>" & vbCrLf Next Response.Write vbTab & "</TR>" & vbCrLf
' Loop through our records Do While rs.AbsolutePage = strPageCurrent And Not rs.EOF Response.Write vbTab & "<TR>" & vbCrLf For x = 1 To rs.Fields.Count Response.Write vbTab & vbTab & "<TD>" Response.Write rs.Fields(x - 1) Response.Write "</TD>" & vbCrLf Next Response.Write vbTab & "</TR>" & vbCrLf
'Move to the next record! rs.MoveNext Loop
'Closing html table tag Response.Write "</TABLE>" & vbCrLf
' Close all objects and clear from Memory rs.Close Set rs = Nothing conn.Close Set conn = Nothing
'Show "previous" and "next" links which navigate between pages If strPageCurrent <> 1 Then Response.Write "<A HREF=""./paging.asp?page=" Response.Write strPageCurrent - 1 Response.Write """>Previous Page</A>" & vbCrLf 'Spacer - inside the if so we don't get it unless needed Response.Write " " & vbCrLf End If If strPageCurrent < strPageCount Then Response.Write "<A HREF=""./paging.asp?page=" Response.Write strPageCurrent + 1 Response.Write """>Next Page</A>" & vbCrLf End If