Jeg bruger følgende kode
<%Option Explicit%>
<%
'Function designed to check if string contants only numbers
Function IsOnlyNumeric(str)
   Dim ianRegEx
   Set ianRegEx = New RegExp
   ianRegEx.Pattern = "[^0-9]"
   ianRegEx.Global = True
   IsOnlyNumeric = (ianRegEx.Test(str) = False)
End Function
%>
<%
'Open database connection (Access)
Dim oConn, StrConn, SQL, oRS
Set oConn = Server.CreateObject("ADODB.Connection") 
StrConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
Server.MapPath("db\db1.mdb") & ";" 
oConn.Open StrConn
'Count the number of records in the database
SQL = "SELECT Count(ID) AS RecordCount FROM tblData"
Set oRS = oConn.Execute(SQL)
Dim intRecordsPerPage, intNumberOfPages, intRecordCount
intRecordsPerPage = 5 'Number of records per page
intRecordCount = oRS("RecordCount") 'Number of records in
database
Dim intPageNumber
'Check to make sure page number in QueryString is valid
If IsOnlyNumeric(Request.QueryString("page")) = True And
Request.QueryString("page") <> "" Then
  intPageNumber = Int(Request.QueryString("page"))
Else
  intPageNumber = 1
End If
'Make sure there are records in the database
If Not oRS.EOF Then
  'Calculate the number of pages based on how many records there
are divided by how many records per page
  'By adding and subtracting 0.5 and using CInt() to round, this
will calculate the most pages needed for how many records there
are
  intNumberOfPages = CInt((intRecordCount - 0.5) /
intRecordsPerPage + 0.5) 
  'This section creates the hyperlinks for the page numbers in a
string to be posted anywhere on the page any number of times
  Dim intPagesAround, intRightPages, intLeftPages
  intPagesAround = 2 'Page number hyperlinks on either side of
select page
  'Show default page numbers on either side
  intRightPages = intPagesAround 
  intLeftPages = intPagesAround
  'Calculates how many page numbers are shown on either side of
the selected page to show a total of intPagesAround * 2 + the
selected page
  If intPageNumber <= intPagesAround Then
    intRightPages = intPagesAround * 2 - intPageNumber + 1
  ElseIf intPageNumber >= intNumberOfPages - intPagesAround Then
    intLeftPages = intPagesAround * 2 - intNumberOfPages +
intPageNumber
  End If
  Dim strPageCount, intPageCount
  'If the page number is greater than 1, then a previous button
is added for easy descending
  If intPageNumber > 1 Then
    strPageCount = strPageCount & "<a
href=""pagenumbers.asp?page=" & intPageNumber - 1 & """>«</a> "
  Else
    strPageCount = strPageCount & "<span style=""color:
#FFFFFF;"">«</span> "
  End If
  For intPageCount = 1 To intNumberOfPages
    If intPageCount <> intPageNumber Then
      If intPageCount <= intPageNumber + intRightPages And
intPageCount >= intPageNumber - intLeftPages Then
        strPageCount = strPageCount & "<a
href=""pagenumbers.asp?page=" & intPageCount & """>" &
intPageCount & "</a> "
      End If
    Else
      strPageCount = strPageCount & intPageCount & " "
    End If
  Next
  'If the page number is less than the total amount of pages,
then a next button is added for easy forwarding
  If intPageNumber < intNumberOfPages Then
    strPageCount = strPageCount & "<a
href=""pagenumbers.asp?page=" & intPageNumber + 1 & """>»</a> "
  Else
    strPageCount = strPageCount & "<span style=""color:
#FFFFFF;"">«</span> "
  End If
  'strPageCount is the string that contains all the page number
hyperlinks
End If
'Grab records from database
SQL = "SELECT ID, fldInfo FROM tblData ORDER BY ID DESC"
Set oRS = oConn.Execute(SQL)
'Move cursor to appropriate record depending on page number
oRS.MoveFirst 'Move cursor to first record
If intPageNumber <= intNumberOfPages And intPageNumber >= 1 Then
'Check to make sure page number entered is in correct parameters
  oRS.Move((intPageNumber - 1) * intRecordsPerPage) 'Move record
cursor to specific position determined by page number given
ElseIf intPageNumber < 1 Then 'Check to see if the QueryString
page number is less than 1
  Response.Redirect("PageNumbers.asp?page=1") 'Reset QueryString
due to user fault
  'OR Move first because QueryString page number is less than 1
  'oRS.MoveFirst 'Moves the record cursor to the begining of the
records, but does not change user's mistake in the QueryString
ElseIf intPageNumber > intNumberOfPages Then 'Check to see if the
QueryString page number is greater than the number of pages
available
  Response.Redirect("PageNumbers.asp?page=" & intNumberOfPages)
'Reset QueryString due to user fault
  'OR Move to last page because QueryString page number is
greater than the number of pages available
  'oRS.Move((intNumberOfPages - 1) * intRecordsPerPage) 'Moves
the record cursor to the end of the last records shown, but does
not change user's mistake in the QueryString
End If
'Display information about records for testing and trouble
shooting errors
Response.Write "<b>Records Per Page: </b>" & intRecordsPerPage &
"<br />"
Response.Write "<b>Record Count: </b>" & intRecordCount & "<br
/>"
Response.Write "<b>Number Of Pages: </b>" & intNumberOfPages &
"<br />"
Response.Write "<b>Page Number: </b>" & intPageNumber & "<br />"
Response.Write "<br />"
'Display page number hyperlinks
Response.Write strPageCount
Response.Write "<br /><br />"
'Display information in the database depending on selected page
number
Dim intCount
Do Until intCount = intRecordsPerPage Or oRS.EOF
  intCount = intCount + 1
  Response.Write oRS("ID") & " " & oRS("fldInfo")
  Response.Write "<br />"
  oRS.MoveNext
Loop
%>
-- 
Vil du lære at kode HTML, XHTML, CSS, SSI, ASP eller ASP.NET?
 - Pædagogiske tutorials på dansk
 - Kom godt i gang med koderne
KLIK HER! => 
http://www.html.dk/tutorials