%
Const adOpenForwardOnly = 0
Const adOpenStatic = 3
Const adLockReadOnly = 1
Const adCmdTable = 2
Const adCmdText = 1
Const adUseClient = 3
Dim iPageSize 'How big our pages are
Dim iPageCount 'The number of pages we get back
Dim iPageCurrent 'The page we want to show
Dim strOrderBy 'A fake parameter used to illustrate passing them
Dim strSQL 'SQL command to execute
Dim objPagingConn 'The ADODB connection object
Dim listingprv 'The ADODB recordset object
Dim iRecordsShown 'Loop controller for displaying just iPageSize records
Dim I 'Standard looping var
Dim IRecordCount
strOrderBy= Request.QueryString("strOrderBy")
Select CASE strOrderBy
Case "Date desc", "Order", "Category", "Type"
Case Else
strOrderBy = "Date Desc"
End Select
' Get parameters
iPageSize = 10 ' You could easily allow users to change this
' Retrieve page to show or default to 1
If Request.QueryString("page") = "" Then
iPageCurrent = 1
Else
iPageCurrent = CInt(Request.QueryString("page"))
End If
strSQL = "SELECT * FROM news order by articledate desc,headline"
Dim objRS
Set objRS = Server.CreateObject ("ADODB.Recordset")
objRS.Open strSQL, connStr, adOpenStatic, adLockReadOnly, adCmdText
objRS.PageSize = iPageSize
' You can change other settings as with any RS
'listingprv.CursorLocation = adUseClient
objRS.CacheSize = iPageSize
' Get the count of the pages using the given page size
iPageCount = objRS.PageCount
iRecordCount = objRS.RecordCount
' If the request page falls outside the acceptable range,
' give them the closest match (1 or max)
If iPageCurrent > iPageCount Then iPageCurrent = iPageCount
If iPageCurrent < 1 Then iPageCurrent = 1
' Check page count to prevent bombing when zero results are returned!
If iRecordCount = 0 Then
Response.Write "
No records found! Add New Listing
"
Else
' Move to the selected page
objRS.AbsolutePage = iPageCurrent
%>
<%
iRecordsShown = 0
Do While iRecordsShown < iPageSize And Not objRS.EOF
Response.Write _
" " & objRS("Headline") & " (" & objRS("ArticleDate") & ")
" & objRS("Subheadline") & "
" & left(objRS("article"),300) & "...
"
iRecordsShown = iRecordsShown + 1
objRS.MoveNext
Loop
End If
' Show "previous" and "next" page links which pass the page to view
' and any parameters needed to rebuild the query. You could just as
' easily use a form but you'll need to change the lines that read
' the info back in at the top of the script.
If iPageCurrent > 1 Then
%>
<<<
<%
End If
' You can also show page numbers:
For I = 1 To iPageCount
If I = iPageCurrent Then
%>
<%= I %>
<%
Else
%>
<%= I %>
<%
End If
Next 'I
If iPageCurrent < iPageCount Then
%>
>>>
<%
End If
%>