回 帖 发 新 帖 刷新版面

主题:一个分页显示的程序,觉得用起来很方便.

我也是从别人那里下的呀,用了很好,推荐给大家啦。

首先,把下面代码粘贴到一个页面中,存为fpage.asp

<%
Sub TurnPage(ByRef Rs_tmp,PageSize) 'Rs_tmp 记录集 PageSize 每页显示的记录条数;
Dim TotalPage '总页数
Dim PageNo '当前显示的是第几页
Dim RecordCount '总记录条数
Rs_tmp.PageSize = PageSize
RecordCount = Rs_tmp.RecordCount
TotalPage = INT(RecordCount / PageSize * -1)*-1
PageNo = Request.QueryString ("PageNo")
'直接输入页数跳转;
If Request.Form("PageNo")<>"" Then PageNo = Request.Form("PageNo")
'如果没有选择第几页,则默认显示第一页;
If PageNo = "" then PageNo = 1
If RecordCount <> 0 then
Rs_tmp.AbsolutePage = PageNo
End If
'获取当前文件名,使得每次翻页都在当前页面进行;
Dim fileName,postion
fileName = Request.ServerVariables("script_name")
postion = InstrRev(fileName,"/")+1
'取得当前的文件名称,使翻页的链接指向当前文件;
fileName = Mid(fileName,postion)
%>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width='690' align='center' cellpadding="2" cellspacing="1">
  <form>
  <tr bgcolor="#FFFFFF">
    <td width="179" height="23" align=center> 总页数:<font color=#ff3333><%=TotalPage%></font>页 当前第<font color=#ff3333><%=PageNo%></font>页</td>
      <td width="285" align="center" bgcolor="#FFFFFF">
        <%If RecordCount = 0 or TotalPage = 1 Then
Response.Write "首页|前页|后页|末页"
Else%>
      <a href="<%=fileName%>?PageNo=1">首页|</a>
      <%If PageNo - 1 = 0 Then
Response.Write "前页|"
Else%>
      <a href="<%=fileName%>?PageNo=<%=PageNo-1%>">前页|</a>
      <%End If
If PageNo+1 > TotalPage Then
Response.Write "后页|"
Else%>
      <a href="<%=fileName%>?PageNo=<%=PageNo+1%>">后页|</a>
      <%End If%>
      <a href="<%=fileName%>?PageNo=<%=TotalPage%>">末页</a>
      <%End If%>
    </td>
      <td width=218 align="center" bgcolor="#FFFFFF"> 转到第
        <%If TotalPage = 1 Then%>
        <input type=text name=PageNo2 size=2 readonly disabled style="background:#d3d3d3" class="text复制">
        <%Else%>
        <input type=text name=PageNo size=2 value="" title=请输入页号,然后回车 class="text复制">
        <%End If%>
        页 <input type="submit" name="Submit" value="提交">
      </td>
  </tr></form>
</table>
<%End Sub%>

然后就是在你需要分页的地方调用就可以了,调用的代码是:
<!--#include file=fpage.asp-->
      <%
Dim RowCount
RowCount = 10 '每页显示的记录条数
Call TurnPage(Rs,RowCount)
'公共翻页模块结束%>

回复列表 (共5个回复)

沙发

Microsoft VBScript 运行时错误 错误 '800a01a8'

缺少对象: 'Rs_tmp'

fpage.asp,行 6


请问怎么解决?

板凳

rs_temp是你的记录集对象,要你自己设的如set rs_temp=server.create("adodb.recordset")

3 楼

哦,楼上的意思是说,在第5句后面加上set rs_temp=server.create("adodb.recordset")
就行了、?

4 楼

来看看我的部份分页代码:
Dim Repeat1__numRows
Dim Records_page
Dim Records_start
Dim Record_numNow
Dim Record_total
Record_total = 0
While (NOT Recordset1.EOF)
Record_total = Record_total+1
Recordset1.MoveNext()
Wend
Recordset1.movefirst
Records_page = 3 '确定每页中的记录数!
Record_numNow = 0

'确定每页的起始记录!
If Trim(cstr(Request.QueryString("No")))<>"" then
Records_start = (Request.QueryString("No")-1)*Records_page+1
Else
Records_start = 0
End if
Repeat1__numRows = Records_page
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows



While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
Record_numNow = Record_numNow+1
    While (Record_numNow < Records_start)
    Record_numNow = Record_numNow+1
    Recordset1.MoveNext()
  Wend
XXXXXXXXXX
Wend


Pages =Round(Record_total/Records_page,10)
If Int(Pages)<Pages then
Pages=Int(Pages)+1
Pages_dir=Pages
End if
No = Pages

<%While (Pages_dir>0)
No=Pages-Pages_dir+1
%>
[<A HREF="ls.asp?No=<%=No %>"><%response.write No %></A>]
<%
Pages_dir=Pages_dir-1
Wend
%>

5 楼

我试过,这段程序不能用!可以显示,但不能分页用

我来回复

您尚未登录,请登录后再回复。点此登录或注册