%
DIM emptyrecordset, firstpass, needrecordset, pagesize, recordsprocessed
DIM stdlistrange, pagingmove, listabsolutepage,rslist, adApproxPosition, pagecount
DIM recordcount, rowcount, i, startrecord
REM -- set flag defaults
EmptyRecordset = False
FirstPass = True
NeedRecordset = False
REM -- initialize page variables
RecordsProcessed = 0
PageSize = ListRange
REM -- get control for going from page to page (from form)
PagingMove = trim(cstr(Request("list_PagingMove")))
REM Get the page we are on
ListAbsolutePage = cint(Request("ListAbsolutePage"))
if IsNull(ListAbsolutePage) then
ListAbsolutePage = 1
end if
REM -- load recordset
Set rsList = Server.CreateObject("ADODB.Recordset")
rsList.CacheSize = PageSize
rsList.open sqlstr,conn,3,1
if Err.Number <> 0 then
Set errorList = Server.CreateObject("Scripting.Dictionary")
errorList.Add "The table could not be found or the database connection failed."
Response.end
end if
REM check for empty record set (beginning and end the same or can't get EOF or BOF)
On Error Resume Next
If rsList.BOF And rsList.EOF Then EmptyRecordset = True
On Error Goto 0
If Err Then EmptyRecordset = True
rsList.PageSize = PageSize
REM -- act on pagemove instruction (from form)
If Not EmptyRecordset Then
REM Determines the Record count by looping through Recordset
Do While Not rsList.EOF
RecordCount = RecordCount + 1
rsList.MoveNext
Loop
if Not rsList.BOF then rsList.MoveFirst
PageCount = Round(RecordCount/PageSize)
REM Determines the Page Size
If PageCount < RecordCount/PageSize then PageCount = PageCount + 1
Select Case PagingMove
Case "<<"
ListAbsolutePage = 1
Case "<"
ListAbsolutePage = ListAbsolutePage - 1
Case ">"
ListAbsolutePage = ListAbsolutePage + 1
Case ">>"
ListAbsolutePage = PageCount
Case Else
End Select
If (ListAbsolutePage - 1) * PageSize > RecordCount or ListAbsolutePage < 1 Then ListAbsolutePage = 1
StartRecord = ((ListAbsolutePage - 1) * PageSize)
For i = 1 to StartRecord
If rsList.EOF then exit for
rsList.MoveNext
Next
If rsList.EOF Then
ListAbsolutePage = ListAbsolutePage - 1
if Not rsList.BOF then rsList.MoveFirst
StartRecord = (ListAbsolutePage - 1) * PageSize
For i = 1 to StartRecord
If rsList.EOF then exit for
rsList.MoveNext
Next
End If
End If
Response.Buffer = True
REM -- show navigation bar (if more than 1 page)
If PageCount > 1 and Not EmptyRecordset Then
%>
<% = RecordCount %> Records Page: <% = ListAbsolutePage %> of <% = PageCount %>
|
|
<%
End If
REM -- show the column headings
%>
<%
REM -- show no rows message if the recordset is empty
If EmptyRecordset Then
%>
|
<%
REM -- else show the row information for each row
Else
RowCount = ((ListAbsolutePage - 1) * PageSize) + 1 %>
<%= listcolumns%>
<% Do %>
<% For I = 1 to 5
If EmptyRecordset Then Exit Do
If RecordsProcessed = PageSize Then Exit Do
If Not FirstPass Then
rsList.MoveNext
Else
FirstPass = False
End If
If rsList.EOF Then Exit Do
RecordsProcessed = RecordsProcessed + 1
%>
<%= ShowRow(rslist) %>
<%
RowCount = RowCount + 1
Next %>
<%
Loop
End If
%>
<%
REM -- show navigation bar (if more than 1 page)
If PageCount > 1 and Not EmptyRecordset Then
%>
<% = RecordCount %> Records Page: <% = ListAbsolutePage %> of <% = PageCount %>
|
|
<%
End If
Response.Flush
%>
<%
rsList.Close
Set rsList = Nothing
%>