<%//建立与employee.mdb数据库的连接。
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=employee.mdb"
//建立emp表的Recordset对象实例rs。
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "emp", conn, 3
PageSize = 10 //pagesize属性指定了每页要显示的记录条数
Page = CLng(Request("Page")) ’string型转化为long型
If Page < 1 Then Page = 1
If Page > rs.PageCount Then Page = rs.PageCount
If Page <> 1 Then
Response.Write "<A HREF=emp1.asp?Page=1>第一页</A>"
Response.Write "<A HREF=emp1.asp?Page=" & (Page-1) & ">上一页</A>"
End If
If Page <> rs.PageCount Then
Response.Write "<A HREF=emp1.asp?Page=" & (Page+1) & ">下一页</A>"
Response.Write "<A HREF=emp1.asp?Page="&rs.PageCount & ">最后一页</A>"
End If
Response.write"页码:" & Page & "/" & rs.PageCount & "</font>"
//每一页的显示
//显示表头
Response.Write "<CENTER><TABLE BORDER=1>"
Response.WRITE "<TR><TD>" & rs.Fields("emp ID").Name & "</TD>"
Response.WRITE "<TD>" & rs.Fields("last name").Name & "</TD>"
Response.WRITE "<TD>" & rs.Fields("first name").Name & "</TD></TR>"
//循环显示每条记录
rs.AbsolutePage = Page //把页码赋给absolutepage属性从而知当前页的首条记录号
For iPage = 1 To rs.PageSize //
Response.WRITE "<TR><TD>" & rs.Fields("emp ID").Value & "</TD>"
Response.WRITE "<TD>" & rs.Fields("first name").Value & "</TD>"
Response.WRITE "<TD>" & rs.Fields("last name").Value & "</TD></TR>"
rs.MoveNext
If rs.EOF Then Exit For
Next
Response.Write "</TABLE></CENTER>"%>
if Pagenum = "" Then Pagenum = 1 //从第一页开始显示
//建立数据库连接和Recordset对象实例rs。
与第一种方法相同,此处略过。
RS.Pagesize = 10 ’ 设置一页中显示的记录条数为10条
// 确定翻页的动作
Select Case Request("NAV")
Case ""
session("Pagenum") = 1
case "First" ’ First Record
session("Pagenum") = 1
case "Prev" ’ Previous Record
if session("Pagenum") > 1 then
session("Pagenum") = session("Pagenum") - 1
End If
case "Next" ’ Next Record
if session("Pagenum")< RS.PageCount then
session("Pagenum") = session("Pagenum") + 1
End if
case "Last" ’ Last Record
session("Pagenum") = RS.PageCount
End Select
RS.Absolutepage = Clng(session("Pagenum")) //确定当前页的第一条记录号
// 显示当前页
同第一种方法,此处略过。
// Nav 翻页按钮设置
<form method="GET" action="emp2.asp">
<input type="submit" name="NAV" Value="首页">
<input type="submit" value="上页" name="NAV">
<input type="submit" value="下页" name="NAV">
<input type="submit" value="末页" name="NAV"></form>
<TABLE ID="Table1" DATASRC="#Recordset1_RDS" DATAPAGESIZE=5> //假定前面设定Recordset控件名为Recordset1。每页显示5条记录。
<THEAD>
<TH ALIGN="left" WIDTH=150>Emp ID</TH> //输出表头
<TH ALIGN="left" WIDTH=200>Last Name</TH>
<TH ALIGN="left" WIDTH=200>First Name</TH>
</THEAD>
<TR>
<TD><DIV DATAFLD="Emp ID"></DIV></TD> //输出表内容
<TD><DIV DATAFLD="Last Name"></DIV></TD>
<TD><DIV DATAFLD="First Name"></DIV></TD>
</TR>
</TABLE>
<SCRIPT LANGUAGE=VBScript>
Function btnPrevious_onclick()
Table1.previousPage()
End Function
Function btnNext_onclick()
Table1.nextPage()
End Function
</SCRIPT>
[1] [2] 下一页
……