<%
Sub ChangePage(url)
'读取通用JavaScript脚本代码
Response.Write "<script language=javascript src=JS/inc.js></script>"
'如果没有页码输入,则当前页默认为第一页,否则当前页为输入的页码
If Request("CurrentPage")="" Or IsNumeric(Request("CurrentPage"))=False Then
objRS.AbsolutePage=1
Else
objRS.AbsolutePage=CLng(Request("CurrentPage"))
End If
'页码跳转的表单
Response.Write "<form method=Get name=MyForm>"
If objRS.PageCount=1 then
Response.Write("[第一页] [上一页] [下一页] [最后一页] ")
Else
If objRS.AbsolutePage=1 then
Response.Write("[第一页] [上一页] ")
Response.Write("[<a href=javascript:PageNext()>下一页</a>] ")
Response.Write("[<a href=javascript:PageLast()>最后一页</a>] ")
Else
If objRS.AbsolutePage=objRS.PageCount then
Response.Write("[<a href=javascript:PageFirst()>第一页</a>] ")
Response.Write("[<a href=javascript:PagePrior()>上一页</a>] ")
Response.Write("[下一页] [最后一页] ")
Else
Response.Write("[<a href=javascript:PageFirst()>第一页</a>] ")
Response.Write("[<a href=javascript:PagePrior()>上一页</a>] ")
Response.Write("[<a href=javascript:PageNext()>下一页</a>] ")
Response.Write("[<a href=javascript:PageLast()>最后一页</a>] ")
End If
End If
End If
'创建下拉列表框,用于选择浏览页码
Response.Write("第<select size=1 name=CurrentPage οnchange=PageCurrent('"&url&"')>")
For i=1 to objRS.PageCount
If objRS.AbsolutePage=i then
Response.Write("<option selected>"&i&"</option>") '当前页码
Else
Response.Write("<option>"&i&"</option>")
End If
Next
Response.Write("</select>页 ")
End Sub
%>
pagesize=分页中记录条数
<!--#include file="conn.asp"-->
<%
sql="select id,title form table order by id desc"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
RS.pagesize=15 '每頁記錄數
page=cint(request("page"))
if page="" or page=0 then
page=1
else
page=page
end if
rs.absolutepage=page
for i=1 to rs.pagesize
if rs.bof or rs.eof then
exit for
end if
%>
<P><%=rs("id")%> <%=rs("title")%></P>
<%
rs.movenext
next
%><br/>
<p>總共有 <font color="#FF0000"><%=rs.recordcount%></font> 條記錄
<%
If Page <= 1 Then
Response.Write "首頁 上一頁 "
End If
If Page > 1 Then
Response.Write "<A HREF=photo.asp?Page=1>首頁</A> "
Response.Write "<A HREF=photo.asp?Page=" & (Page-1) & ">上一頁</A> "
End If
If Page < RS.PageCount Then
Response.Write "<A HREF=photo.asp?Page=" & (Page+1) & ">下一頁</A> "
Response.Write "<A HREF=photo.asp?Page=" & RS.PageCount & ">末頁</A> "
End If
If Page >= RS.PageCount Then
Response.Write "下一頁 末頁 "
End If
%>
<select name="Page" size="1" οnchange="window.location.href=this.value" class="user">
<%For j=1 to rs.pagecount%>
<option value="photo.asp?page=<%=j%>"<%if j=Page then%>selected<%end if%>><%=j%></option>
<%Next%>
</select> 第<%=Page%>頁/共<%=RS.PageCount%>頁</P>
完整存储过程分页
面的SET ROWCOUNT n语句:
declare @pagesize int --每页纪录数
declare @reccounts int --数据库总的纪录数
declare @pagecounts int --根据每页纪录数和数据库总的纪录数返回的总页数
declare @intBeginID int --特定页的第一条(最小)纪录
declare @intRowCount int --临时变量
declare @currentpage int --当前页
select @pagesize=10 --每页10条纪录
select @currentpage=5 --设置当前页
select @reccounts=count(1) from Procurement_Requisition --返回所有纪录数
if @reccounts/@pagesize*@pagesize=@reccounts
set @pagecounts=@reccounts/@pagesize --返回总页数
else
set @pagecounts=@reccounts/@pagesize+1 --返回总页数
set @intRowCount=(@currentpage-1)*@pagesize+1 --特定页的第一条(最小)纪录在所有纪录中的位置(使用了order by)
SET ROWCOUNT @intRowCount
select @intBeginID=pr_no from Procurement_Requisition order by pr_no
SET ROWCOUNT @pagesize
print @intBeginID
select * from Procurement_Requisition where pr_NO>=@intBeginID order by pr_no
SET ROWCOUNT 0