代码很典型,大家自己看看把。
<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit %>
<!--#include virtual="/ADOVBS.inc"-->
<%
设置你一页要显示多少记录
Const NumPerPage = 10
取得当前所在页
Dim CurPage
If Request.QueryString("CurPage") = "" then
CurPage = 1 Were on the first page
Else
CurPage = Request.QueryString("CurPage")
End If
Dim conn
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=MyDB"
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")
设置游标属性
rs.CursorLocation = adUseClient
设置缓存大小 = 每页需显示的记录数目
rs.CacheSize = NumPerPage
Dim strSQL
strSQL = "SELECT Name,Salary FROM Employee ORDER BY Name"
rs.Open strSQL, Conn
rs.MoveFirst
rs.PageSize = NumPerPage
计算最多有多少页
Dim TotalPages
TotalPages = rs.PageCount
rs.AbsolutePage = CurPage
Dim count
%>
<HTML>
<BODY>
<B>姓名 - 薪水</B><BR>
<%
Count = 0
Do While Not rs.EOF And Count < rs.PageSize
Response.Write(rs("Name") & " - " & rs("Salary") & "<BR>")
Count = Count + 1
rs.MoveNext
Loop
Response.Write("第 " & CurPage & " 页,共 " & TotalPages & "页<P>")
显示 Next / Prev 按钮
if CurPage > 1 then
Response.Write("<INPUT TYPE=BUTTON VALUE=PREV
ONCLICK=""document.location.href=thisfile.asp?curpage=" & curpage - 1
& ";"">")
End If
if CInt(CurPage) <> CInt(TotalPages) then
Response.Write("<INPUT TYPE=BUTTON VALUE=NEXT
ONCLICK=""document.location.href=thisfile.asp?curpage=" & curpage + 1
& ";"">")
End If
%>
</BODY>
</HTML>