关于一个ASP 分页系统的问题!

wcnjy 2009-08-24 05:20:05
这是我在网上下的一个ASP 分页系统,但是使用后发现一个问题,当数据记录为空时,读取便会出错:

错误类型:
ADODB.Recordset (0x800A0BCD)
BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。
/浙江昌达食品调味网/浙江昌达/inc/page_class.asp, 第 104 行

以下是 分页代码 -----page_class.asp------

<%
'================================================
'/印象分页类(Impression_Page v1.5)
'/作者:纯属.印象(QQ:442398600、Email:jhy0029@qq.com
'================================================
'/*第一页按钮显示样式*/
Const PageBtn_First = "首页"
'/*前一页按钮显示样式*/
Const PageBtn_Prev = "上一页"
'/*下一页按钮显示样式*/
Const PageBtn_Next = "下一页"
'/*最后一页按钮显示样式*/
Const PageBtn_Last = "尾页"

Const Page_Nolink_Color = "#808080"

Class Pagination_Class

Private Page
Private Page_RS
Private Page_Num
Private Page_URL
Private Page_URLstr
Private Page_Navigation_Type
Private Error_Str

Public Property Let GetRs(ByRef obj_RS)
If IsObject(obj_RS) Then
Set Page_RS = obj_RS
End If
End Property

'/*Get_Pagenum得到每页显示数*/
Public Property Let Get_Pagenum(Val)
If Val = "" Or IsEmpty(Val) Then
Page_Num = 10
Else
If IsNumeric(Val) = False Then
Error_Str = Error_Str & "每页显示信息数不正确!"
Call Show_Error(Error_Str)
Else
Page_Num = Clng(Val)
End If
End If
End Property

'/*分页文件地址*/
Public Property Let URL_Path(str_URL)
If str_URL = "" Or IsEmpty(str_URL) Then
Error_Str = Error_Str & "分页地址不能为空!"
Call Show_Error(Error_Str)
Else
Page_URL = Cstr(str_URL)
End If
End Property

'/*分页导航显示样式*/
Public Property Let Page_Navtype(Val)
If Val = "" Or IsEmpty(Val) Then
Page_Navigation_Type = 2
Else
If Val < 1 Or Val > 2 Then
Error_Str = Error_Str & "分页导航参数不正确!"
Call Show_Error(Error_Str)
Else
Page_Navigation_Type = Clng(Val)
End If
End If
End Property

Private Sub Class_initialize()

End Sub

Private Sub Class_Terminate()
Page_RS.Close
Set Page_RS = Nothing
End Sub

Public Sub Pagination_Init()
Dim Page_Str
Page_Str = Replace(Replace(Trim(Request("page")),"'",""),"%","")
Page = Page_Str
If Page = "" Or IsEmpty(Page) Then
Page = 1
Else
If Check_Numeric(Page) = False Then
Page = 1
Else
Page = Clng(Page)
End If

If Int(Page) < 1 Or Int(Page) <= 0 Then
Page = 1
Else
If Page >= Page_RS.PageCount Then
Page = Page_RS.PageCount
Else
Page = Clng(Page)
End If
End If
End If
Page_RS.PageSize = Page_Num
Page_RS.AbsolutePage = Page
End Sub

Public Sub Pagination_Navigation()
Page_URLstr = GetURL(Page_URL)
'显示分页信息,各个模块根据自己要求更改显求位置
'Response.Write "<table border=""0"" cellpadding=""0"" cellspacing=""0"">"
'Response.Write "<tr>"
'Response.Write "<td>"

Nav_Htmlstr = Show_FirstPrv
Response.Write Nav_Htmlstr &" "

If Page_Navigation_Type = 1 Then
Nav_Htmlstr = Show_NumBtn
Response.Write Nav_Htmlstr
End If

Nav_Htmlstr = Show_NextLast
Response.Write Nav_Htmlstr

Nav_Htmlstr = Show_PageInfo
Response.Write " "& Nav_Htmlstr

Nav_Htmlstr = Show_PageOption
Response.Write Nav_Htmlstr

'Response.Write "</td>"
'Response.Write "</tr>"
End Sub

'/*Show_FirstPrv显示首页、前一页*/
Private Function Show_FirstPrv()
Dim str_tmp, int_Prvpage
If Page <= 1 Then
str_tmp = "<font color='"& Page_Nolink_Color &"'>"& PageBtn_First &"</font> <font color='"& Page_Nolink_Color &"'>"& PageBtn_Prev &"</font>"
Else
int_Prvpage = Page-1
str_tmp = "<a href='"& Page_URLstr &"page=1'>"& PageBtn_First &"</a> <a href='"& Page_URLstr &"page="& Cstr(int_Prvpage) &"'>" & PageBtn_Prev &"</a>"
End If
Show_FirstPrv = str_tmp
End Function

'/*Show_NextLast显示下一页、末页*/
Private Function Show_NextLast()
Dim str_tmp, int_Nextpage
If Page >= Page_RS.PageCount Then
str_tmp = "<font color='"& Page_Nolink_Color &"'>"& PageBtn_Next &"</font> <font color='"& Page_Nolink_Color &"'>"& PageBtn_Last &"</font>"
Else
Int_NextPage = Page+1
str_tmp = "<a href='"& Page_URLstr &"page="& Cstr(Int_NextPage) &"'>" & PageBtn_Next &"</a> <a href='"& Page_URLstr &"page="& Cstr(Page_RS.PageCount) &"'>"& PageBtn_Last &"</a>"
End If
Show_NextLast = str_tmp
End Function

'/*显示数字导航*/
Private Function Show_NumBtn()
Dim Startpage, Endpage
Startpage = Clng((Page \ 10)*10+1)
If Page Mod 10 = 0 Then Startpage = Clng((Page \ 10)*10-9)
Endpage = Startpage+9

For Startpage = Startpage to Endpage
str_tmp = str_tmp &"[<a href='"& Page_URLstr &"page="& Cstr(Startpage) &"'>"
If Startpage = Page Then
str_tmp = str_tmp &"<font color='#FF0000'>"& Startpage &"</font>"
Else
str_tmp = str_tmp & Startpage
End If
str_tmp = str_tmp &"</a>] "
If Startpage >= Page_RS.PageCount Then Exit For
Next
Show_NumBtn = str_tmp
End Function

'/*显示OPTION跳转*/
Private Function Show_PageOption()
Dim str_tmp, i
str_tmp = vbcrlf
str_tmp = str_tmp & "<script language=""javascript"" type=""text/javascript"">"& vbcrlf
str_tmp = str_tmp & "function jump_page(VALUE_STR){"& vbcrlf
str_tmp = str_tmp & "location='"& Page_URLstr &"page='+VALUE_STR"& vbcrlf
str_tmp = str_tmp & "}"& vbcrlf
str_tmp = str_tmp & "</script>"& vbcrlf
str_tmp = str_tmp & "<select onChange=""jump_page(this.value)"">"& vbcrlf
For i = 1 to Page_RS.PageCount
str_tmp = str_tmp & "<option value='"& i &"'"
If Clng(i) = Page Then
str_tmp = str_tmp & " selected"
End If
str_tmp = str_tmp & ">第"& i &"页</option>"& vbcrlf
Next
str_tmp = str_tmp & "</select>"
Show_PageOption = str_tmp
End Function

'/*ShowPageInfo分页信息*/
'/*更据要求自行修改*/
Private Function Show_PageInfo()
Dim str_tmp
str_tmp = "页次:"& Page &"/"& Page_RS.PageCount &"页 共"& Page_RS.RecordCount &"条 "& Page_Num &"条/页"
Show_PageInfo = str_tmp
End Function

Private Function GetURL(strUrl)
If strUrl = "" Or IsEmpty(strUrl) Then
GetURL = ""
Exit Function
End If

If InStr(strUrl,"?") < Len(strUrl) Then
If InStr(strUrl,"?") > 1 Then
If InStr(strUrl,"&") < len(strUrl) Then
GetURL = strUrl & "&"
Else
GetURL = strUrl
End If
Else
GetURL = strUrl & "?"
End If
Else
GetURL = strUrl
End If
End Function

Private Function Check_Numeric(VarString)
If VarString = "" Or IsEmpty(VarString) Then
Exit Function
End If

Dim regEx, Matches
Set regEx = New RegExp
regEx.Pattern = "^\d+$"
regEx.IgnoreCase = True
regEx.Global = True
Matches = regEx.Test(VarString)
Check_Numeric = Matches
End Function

Private Sub Show_Error(STR)
If STR <> "" Then
Response.Write STR
Response.End
End If
End Sub

End Class
%>


以下是调用代码--------news.asp-----------

		  <div class="new">
<ul>
<%Dim Obj_CreatePage, Page_Infonum, P_I
Set Obj_CreatePage = New Pagination_Class
set rs=server.CreateObject("adodb.recordset")
if request("t_id")<>"" then
sql= "select * from ku_news where class="&request("t_id")&" "
Obj_CreatePage.URL_Path = "news.asp?t_id="&request("t_id")&"" '分页文件地址
end if
if request("t_id")="" then
sql= "select * from ku_news"
Obj_CreatePage.URL_Path = "news.asp" '分页文件地址
end if
sql=sql&" order by id desc"
rs.open sql,conn,1,1

Page_Infonum = 10 '每页显示信息数
Obj_CreatePage.GetRs = RS
Obj_CreatePage.Get_Pagenum = Page_Infonum

Obj_CreatePage.Page_Navtype = 1 '分页导航(1为数字,2为文字;默认为文字导航)
Call Obj_CreatePage.Pagination_Init() '初始化分页
%>
<%
If Not(RS.Bof and RS.Eof) Then
For P_I = 1 to Page_Infonum
If RS.Eof Then
Exit For
End If
%>
<li><a id="l" href="#"><%=rs("title")%></a><a id="d">[2009-01-08]</a></li>
<%
rs.movenext
Next
end if
%>
</ul>
</div>
...全文
96 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
pigpig2009 2009-08-24
  • 打赏
  • 举报
回复
判断下 记录集是否为空 的时候显示空数据不就行了!
davcsevil 2009-08-24
  • 打赏
  • 举报
回复
哪用那么麻烦。。。。。。。
还不如用这个代码

Sub Pagination_Init(objRS, Page_Size) '数据分页模块
objRS.PageSize = Page_Size
Page = Trim(Request.QueryString("Page"))
If Not (IsNumeric(Page)) Then Page = 1
If Int(Page) > Int(objRS.PageCount) Or Int(Page) < 1 Then
Page = 1
Else
Page = Int(Page)
End If
objRS.AbsolutePage = Page
End Sub

Function Pagination(objRS, PageUrl, intFCount) '数据分页模块
Response.Write "<form name='form' method='post' action=url>"
If PageUrl <> "" Then
PageUrl = PageUrl & "&"
Else
PageUrl = "?"
End If
If Page <= 1 Then
Response.Write "[首页][上一页] "
Else
Response.Write "[<a href='" & PageUrl & "Page=1'>首页</a> ]"
Response.Write "[<a href='" & PageUrl & "Page=" & (Page - 1) & "'>上一页</a>]"
End If
If Page >= objRS.PageCount Then
Response.Write "[下一页][尾页]"
Else
Response.Write "[<a href='" & PageUrl & "Page=" & (Page + 1) & "'>下一页</a>]"
Response.Write "[<a href='" & PageUrl & "Page=" & objRS.PageCount & "'>尾页</a>]"
End If
Response.Write "转到:<select name='Page' size='1' onchange=""javascript:window.location='" & PageUrl & "Page=" & "'+this.options[this.selectedIndex].value;"">"
For i = 1 To objRS.PageCount
If i = Page Then
Response.Write "<option selected value=" & i & ">" & "第" & i & "页" & "</option>"
Else
Response.Write "<option value=" & i & ">" & "第" & i & "页" & "</option>"
End If
Next
Response.Write "</select>"
Response.Write "[共<Font color='Red'><b>" & objRS.RecordCount & "</b></Font>条记录]"
Response.Write "[页次<Font color='Red'>" & Page & "</Font>/" & objRS.PageCount & "页]"
End Function



调用:
rs.Open sqlt, conn, 1, 1
Call Pagination_Init(rs, Page_Size)
intRecCount = 0
intFCount = rs.Fields.Count - 1

Do While Not rs.EOF And intRecCount < rs.PageSize


'response.write rs...



rs.MoveNext
intRecCount = intRecCount + 1
s = s + 1
Loop

Call Pagination(rs, req, intFCount)


hookee 2009-08-24
  • 打赏
  • 举报
回复

<div class="new">
<%Dim Obj_CreatePage, Page_Infonum, P_I
Set Obj_CreatePage = New Pagination_Class
set rs=server.CreateObject("adodb.recordset")
if request("t_id")<>"" then
sql= "select * from ku_news where class="&request("t_id")&" "
Obj_CreatePage.URL_Path = "news.asp?t_id="&request("t_id")&"" '分页文件地址
end if
if request("t_id")="" then
sql= "select * from ku_news"
Obj_CreatePage.URL_Path = "news.asp" '分页文件地址
end if
sql=sql&" order by id desc"
rs.open sql,conn,1,1
If Not (rs.eof and rs.bof) Then
%>
<ul>
<%
Page_Infonum = 10 '每页显示信息数
Obj_CreatePage.GetRs = RS
Obj_CreatePage.Get_Pagenum = Page_Infonum

Obj_CreatePage.Page_Navtype = 1 '分页导航(1为数字,2为文字;默认为文字导航)
Call Obj_CreatePage.Pagination_Init() '初始化分页
%>
<%
For P_I = 1 to Page_Infonum
If RS.Eof Then
Exit For
End If
%>
<li><a id="l" href="#"><%=rs("title")%></a><a id="d">[2009-01-08]</a></li>
<%
rs.movenext
Next
%>
</ul>
<%
else
Response.Write "无记录"
end if
%>
</div>
loveinet_168 2009-08-24
  • 打赏
  • 举报
回复
顶。。。

28,405

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧