<
%
'******************************************************************************
'类名:cPage
'功能:ASP分页
'作者:inrg
'******************************************************************************
Class cPage
Private page
Public pagesize
Private cRs
Private isEof
Private Sub class_initialize()
pagesize = 10 ' 初始页大小
isEof = False
page = Request.QueryString( " page " )
If Trim ( page ) = "" Or Trim ( page ) = " 0 " Then
page = 1
Else
page = cInt ( Trim ( page ) )
End If
End Sub
Private Sub class_terminate()
set cRs = nothing
set cCom = nothing
End Sub
Public Sub setRs( rs )
Set cRs = rs
If rs.Eof Then
isEof = True
Exit Sub
End If
cRs.PageSize = pagesize
cRs.AbsolutePage = page
End Sub
' 设置查询字符串
Private Function setUrl( querystring, str , value )
Dim maxArr, minArr, i, m, strTmp, bool
maxArr = Split ( querystring, " & " )
strTmp = ""
bool = True
For i = 0 To Ubound ( maxArr )
minArr = Split ( maxArr( i ), " = " )
If Trim ( minArr( 0 ) ) = Trim ( str ) Then
bool = False
minArr( 1 ) = value
End If
If i = Ubound ( maxArr ) Then
strTmp = strTmp & Trim ( minArr( 0 ) ) & " = " & Trim ( minArr( 1 ) )
Else
strTmp = strTmp & Trim ( minArr( 0 ) ) & " = " & Trim ( minArr( 1 ) ) & " & "
End If
Next
If bool = True Then
If trim ( querystring ) = "" Then
strTmp = Trim ( str ) & " = " & Trim ( value )
Else
strTmp = Trim ( querystring ) & " & " & Trim ( str ) & " = " & Trim ( value )
End If
End If
setUrl = strTmp
End Function
' 获得跳转页面网址
Public Function getUrl( cPage )
Dim servername, scriptname, serverport, querystring, url
servername = Request.ServerVariables( " SERVER_NAME " )
scriptname = Request.ServerVariables( " SCRIPT_NAME " )
serverport = Request.ServerVariables( " SERVER_PORT " )
querystring = Request.ServerVariables( " Query_String " )
querystring = setUrl(querystring, " page " , cPage)
If Trim ( serverport ) = " 80 " Then
url = " http:// " & Trim (servername) & Trim (scriptname) & " ? " & Trim (querystring)
Else
url = " http:// " & Trim (servername) & " : " & Trim (serverport) & Trim (scriptname) & " ? " & Trim (querystring)
End If
getUrl = url
End Function
' 获得分页代码(底部 首页)
Public Function getFirstPageStr( firststr )
If isEof Then
getFirstPageStr = ""
Exit Function
End If
If page <= 1 Then
getFirstPageStr = " <a> " & firststr & " </a> "
Else
getFirstPageStr = " <a href= " & getUrl( 1 ) & " > " & firststr & " </a> "
End If
End Function
' 获得分页代码(底部 尾页)
Public Function getEndPageStr( Endstr )
If isEof Then
getEndPageStr = ""
Exit Function
End If
If page >= cRs.PageCount Then
getEndPageStr = " <a> " & Endstr & " </a> "
Else
getEndPageStr = " <a href= " & getUrl( cRs.PageCount ) & " > " & Endstr & " </a> "
End If
End Function
' 获得分页代码(底部 上一页)
Public Function getBeforePageStr( beforestr )
If isEof Then
getBeforePageStr = ""
Exit Function
End If
If page <= 1 Then
getBeforePageStr = " <a> " & beforestr & " </a> "
Else
getBeforePageStr = " <a href= " & getUrl( page - 1 ) & " > " & beforestr & " </a> "
End If
End Function
' 获得分页代码(底部 下一页)
Public Function getNextPageStr( nextstr )
If isEof Then
getNextPageStr = ""
Exit Function
End If
If page >= cRs.PageCount Then
getNextPageStr = " <a> " & nextstr & " </a> "
Else
getNextPageStr = " <a href= " & getUrl( page + 1 ) & " > " & nextstr & " </a> "
End If
End Function
' 获得分页代码(底部 下拉)
Public Function getGoPageStr( gostr )
If isEof Then
getGoPageStr = ""
Exit Function
End If
Dim i, str
str = gostr & " <select name='page' onChange=javascript:document.forms[0].submit()> "
For i = 1 To cRs.PageCount
If i = page Then
str = str & " <option value= " & i & " selected> " & i & " </option> "
Else
str = str & " <option value= " & i & " > " & i & " </option> "
End If
Next
str = str & " </select> "
getGoPageStr = str
End Function
End Class
% >
Class cPage
Private page
Public pagesize
Private cRs
Private isEof
Private Sub class_initialize()
pagesize = 10 ' 初始页大小
isEof = False
page = Request.QueryString( " page " )
If Trim ( page ) = "" Or Trim ( page ) = " 0 " Then
page = 1
Else
page = cInt ( Trim ( page ) )
End If
End Sub
Private Sub class_terminate()
set cRs = nothing
set cCom = nothing
End Sub
Public Sub setRs( rs )
Set cRs = rs
If rs.Eof Then
isEof = True
Exit Sub
End If
cRs.PageSize = pagesize
cRs.AbsolutePage = page
End Sub
' 设置查询字符串
Private Function setUrl( querystring, str , value )
Dim maxArr, minArr, i, m, strTmp, bool
maxArr = Split ( querystring, " & " )
strTmp = ""
bool = True
For i = 0 To Ubound ( maxArr )
minArr = Split ( maxArr( i ), " = " )
If Trim ( minArr( 0 ) ) = Trim ( str ) Then
bool = False
minArr( 1 ) = value
End If
If i = Ubound ( maxArr ) Then
strTmp = strTmp & Trim ( minArr( 0 ) ) & " = " & Trim ( minArr( 1 ) )
Else
strTmp = strTmp & Trim ( minArr( 0 ) ) & " = " & Trim ( minArr( 1 ) ) & " & "
End If
Next
If bool = True Then
If trim ( querystring ) = "" Then
strTmp = Trim ( str ) & " = " & Trim ( value )
Else
strTmp = Trim ( querystring ) & " & " & Trim ( str ) & " = " & Trim ( value )
End If
End If
setUrl = strTmp
End Function
' 获得跳转页面网址
Public Function getUrl( cPage )
Dim servername, scriptname, serverport, querystring, url
servername = Request.ServerVariables( " SERVER_NAME " )
scriptname = Request.ServerVariables( " SCRIPT_NAME " )
serverport = Request.ServerVariables( " SERVER_PORT " )
querystring = Request.ServerVariables( " Query_String " )
querystring = setUrl(querystring, " page " , cPage)
If Trim ( serverport ) = " 80 " Then
url = " http:// " & Trim (servername) & Trim (scriptname) & " ? " & Trim (querystring)
Else
url = " http:// " & Trim (servername) & " : " & Trim (serverport) & Trim (scriptname) & " ? " & Trim (querystring)
End If
getUrl = url
End Function
' 获得分页代码(底部 首页)
Public Function getFirstPageStr( firststr )
If isEof Then
getFirstPageStr = ""
Exit Function
End If
If page <= 1 Then
getFirstPageStr = " <a> " & firststr & " </a> "
Else
getFirstPageStr = " <a href= " & getUrl( 1 ) & " > " & firststr & " </a> "
End If
End Function
' 获得分页代码(底部 尾页)
Public Function getEndPageStr( Endstr )
If isEof Then
getEndPageStr = ""
Exit Function
End If
If page >= cRs.PageCount Then
getEndPageStr = " <a> " & Endstr & " </a> "
Else
getEndPageStr = " <a href= " & getUrl( cRs.PageCount ) & " > " & Endstr & " </a> "
End If
End Function
' 获得分页代码(底部 上一页)
Public Function getBeforePageStr( beforestr )
If isEof Then
getBeforePageStr = ""
Exit Function
End If
If page <= 1 Then
getBeforePageStr = " <a> " & beforestr & " </a> "
Else
getBeforePageStr = " <a href= " & getUrl( page - 1 ) & " > " & beforestr & " </a> "
End If
End Function
' 获得分页代码(底部 下一页)
Public Function getNextPageStr( nextstr )
If isEof Then
getNextPageStr = ""
Exit Function
End If
If page >= cRs.PageCount Then
getNextPageStr = " <a> " & nextstr & " </a> "
Else
getNextPageStr = " <a href= " & getUrl( page + 1 ) & " > " & nextstr & " </a> "
End If
End Function
' 获得分页代码(底部 下拉)
Public Function getGoPageStr( gostr )
If isEof Then
getGoPageStr = ""
Exit Function
End If
Dim i, str
str = gostr & " <select name='page' onChange=javascript:document.forms[0].submit()> "
For i = 1 To cRs.PageCount
If i = page Then
str = str & " <option value= " & i & " selected> " & i & " </option> "
Else
str = str & " <option value= " & i & " > " & i & " </option> "
End If
Next
str = str & " </select> "
getGoPageStr = str
End Function
End Class
% >
使用实例:
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
有什么问题还请大家发表评论!