ASP經(jīng)典分頁類
更新時間:2007年03月12日 00:00:00 作者:
ASP經(jīng)典分頁類
出處
'=====================================================================
'XDOWNPAGE ASP版本
'版本 1.00
'Code by zykj2000
'Email: zykj_2000@163.net
'BBS: http://bbs.513soft.net
'本程序可以免費使用、修改,希望我的程序能為您的工作帶來方便
'但請保留以上請息
'
'程序特點
'本程序主要是對數(shù)據(jù)分頁的部分進(jìn)行了封裝,而數(shù)據(jù)顯示部份完全由用戶自定義,
'支持URL多個參數(shù)
'
'使用說明
'程序參數(shù)說明
'PapgeSize 定義分頁每一頁的記錄數(shù)
'GetRS 返回經(jīng)過分頁的Recordset此屬性只讀
'GetConn 得到數(shù)據(jù)庫連接
'GetSQL 得到查詢語句
'程序方法說明
'ShowPage 顯示分頁導(dǎo)航條,唯一的公用方法
'
'例:
'
' '包含文件
'
' Set mypage=new xdownpage '創(chuàng)建對象
' mypage.getconn=conn '得到數(shù)據(jù)庫連接
' mypage.getsql="select * from productinfo order by id asc"
' mypage.pagesize=5 '設(shè)置每一頁的記錄條數(shù)據(jù)為5條
' set rs=mypage.getrs() '返回Recordset
' mypage.showpage() '顯示分頁信息,這個方法可以,在set rs=mypage.getrs()以后
' 任意位置調(diào)用,可以調(diào)用多次
' for i=1 to mypage.pagesize '接下來的操作就和操作一個普通Recordset對象一樣操作
' if not rs.eof then '這個標(biāo)記是為了防止最后一頁的溢出
' response.write rs(0) & "
" '這里就可以自定義顯示方式了
' rs.movenext
' else
' exit for
' end if
' next
'
'=====================================================================
Const Btn_First="9" '定義第一頁按鈕顯示樣式
Const Btn_Prev="3" '定義前一頁按鈕顯示樣式
Const Btn_Next="4" '定義下一頁按鈕顯示樣式
Const Btn_Last=":" '定義最后一頁按鈕顯示樣式
Const XD_Align="center" '定義分頁信息對齊方式
Const XD_Width="100%" '定義分頁信息框大小
Const XD_Height="20"
Class Xdownpage
Private XD_PageCount,XD_Conn,XD_Rs,XD_SQL,XD_PageSize,Str_errors,int_curpage,str_URL,int_totalPage,int_totalRecord
'=================================================================
'PageSize 屬性
'設(shè)置每一頁的分頁大小
'=================================================================
Public Property Let PageSize(int_PageSize)
If IsNumeric(Int_Pagesize) Then
XD_PageSize=CLng(int_PageSize)
Else
str_error=str_error & "PageSize的參數(shù)不正確"
ShowError()
End If
End Property
Public Property Get PageSize
If XD_PageSize="" or (not(IsNumeric(XD_PageSize))) Then
PageSize=10
Else
PageSize=XD_PageSize
End If
End Property
'=================================================================
'GetRS 屬性
'返回分頁后的記錄集
'=================================================================
Public Property Get GetRs()
Set XD_Rs=Server.createobject("adodb.recordset")
XD_Rs.PageSize=PageSize
XD_Rs.Open XD_SQL,XD_Conn,1,1
If not(XD_Rs.eof and XD_RS.BOF) Then
If int_curpage>XD_RS.PageCount Then
int_curpage=XD_RS.PageCount
End If
XD_Rs.AbsolutePage=int_curpage
End If
Set GetRs=XD_RS
End Property
'================================================================
'GetConn 得到數(shù)據(jù)庫連接
'
'================================================================
Public Property Let GetConn(obj_Conn)
Set XD_Conn=obj_Conn
End Property
'================================================================
'GetSQL 得到查詢語句
'
'================================================================
Public Property Let GetSQL(str_sql)
XD_SQL=str_sql
End Property
'==================================================================
'Class_Initialize 類的初始化
'初始化當(dāng)前頁的值
'
'==================================================================
Private Sub Class_Initialize
'========================
'設(shè)定一些參數(shù)的黙認(rèn)值
'========================
XD_PageSize=10 '設(shè)定分頁的默認(rèn)值為10
'========================
'獲取當(dāng)前面的值
'========================
If request("page")="" Then
int_curpage=1
ElseIf not(IsNumeric(request("page"))) Then
int_curpage=1
ElseIf CInt(Trim(request("page")))<1 Then
int_curpage=1
Else
Int_curpage=CInt(Trim(request("page")))
End If
End Sub
'====================================================================
'ShowPage 創(chuàng)建分頁導(dǎo)航條
'有首頁、前一頁、下一頁、末頁、還有數(shù)字導(dǎo)航
'
'====================================================================
Public Sub ShowPage()
Dim str_tmp
int_totalRecord=XD_RS.RecordCount
If int_totalRecord<=0 Then
str_error=str_error & "總記錄數(shù)為零,請輸入數(shù)據(jù)"
Call ShowError()
End If
If int_totalRecord int_TotalPage=1
Else
If int_totalRecord mod PageSize =0 Then
int_TotalPage = Int(int_TotalRecord / XD_PageSize * -1)*-1
Else
int_TotalPage = Int((int_TotalRecord / XD_PageSize * -1)*-1)+1
End If
End If
If Int_curpage>int_Totalpage Then
int_curpage=int_TotalPage
End If
'===============================================================================
'顯示分頁信息,各個模塊根據(jù)自己要求更改顯求位置
'===============================================================================
response.write " "
str_tmp=ShowFirstPrv
response.write str_tmp
str_tmp=showNumBtn
response.write str_tmp
str_tmp=ShowNextLast
response.write str_tmp
str_tmp=ShowPageInfo
response.write str_tmp
'Response.write " "
ShowGoto
response.write "
"
End Sub
'====================================================================
'ShowFirstPrv 顯示首頁、前一頁
'
'
'====================================================================
Private Function ShowFirstPrv()
Dim Str_tmp,int_prvpage
If int_curpage=1 Then
str_tmp=Btn_First&" "&Btn_Prev
Else
int_prvpage=int_curpage-1
str_tmp=""&Btn_First&" "& Btn_Prev&""
End If
ShowFirstPrv=str_tmp
End Function
'====================================================================
'ShowNextLast 下一頁、末頁
'
'
'====================================================================
Private Function ShowNextLast()
Dim str_tmp,int_Nextpage
If Int_curpage>=int_totalpage Then
str_tmp=Btn_Next & " " & Btn_Last
Else
Int_NextPage=int_curpage+1
str_tmp=""&Btn_Next&" "& Btn_Last&""
End If
ShowNextLast=str_tmp
End Function
'====================================================================
'ShowNumBtn 數(shù)字導(dǎo)航
'
'
'====================================================================
'Private Function showNumBtn()
' Dim i,str_tmp
' For i=1 to int_totalpage
' str_tmp=str_tmp & "["&i&"] "
' Next
' showNumBtn=str_tmp
'
'End Function
'====================================================================
'ShowNumBtn 修改后的數(shù)字導(dǎo)航
'
'====================================================================
Function showNumBtn()
Dim i,str_tmp,end_page,start_page
if int_curpage>4 then
if int_curpage+2 start_page=int_curpage-2
end_page=int_curpage+2
else
start_page=int_totalpage-4
end_page=int_totalpage
end if
else
start_page=1
if int_totalpage>5 then
end_page=5
else
end_page=int_totalpage
end if
end if
For i=start_page to end_page
str_tmp=str_tmp & " ["&i&"] "
Next
showNumBtn=str_tmp
End Function
'====================================================================
'ShowGoto 頁面跳轉(zhuǎn)
'
'
'====================================================================
Private Function ShowGoto()
Dim M_item
'========================================================
'將返回的Url參數(shù)逐個的寫入隱藏域中,以便與參數(shù)繼續(xù)傳遞
'========================================================
For Each M_item In Request.QueryString
If InStr("page",M_Item)=0 Then '從參數(shù)中除去 "page" 的值
Response.Write ""
End If
Next
'========================================================
response.write " 轉(zhuǎn)到第:"
response.write " 頁 "
End Function
'====================================================================
'ShowPageInfo 分頁信息
'更據(jù)要求自行修改
'
'====================================================================
Private Function ShowPageInfo()
Dim str_tmp
str_tmp=" [頁次:"&int_curpage&"/"&int_totalpage&"頁] [共"&int_totalrecord&"條] ["&XD_PageSize&"條/頁]"
ShowPageInfo=str_tmp
End Function
'====================================================================
'修改后的獲取當(dāng)前Url參數(shù)的函數(shù)
'Codeing by Redsun
'====================================================================
Private Function GetUrl()
Dim ScriptAddress, M_ItemUrl, M_item
ScriptAddress = CStr(Request.ServerVariables("SCRIPT_NAME"))&"?"'取得當(dāng)前地址
If (Request.QueryString <> "") Then
M_ItemUrl = ""
For Each M_item In Request.QueryString
If InStr("page",M_Item)=0 Then
M_ItemUrl = M_ItemUrl & M_Item &"="& Server.URLEncode(Request.QueryString(""&M_Item&"")) & "&"
End If
Next
ScriptAddress = ScriptAddress & M_ItemUrl'取得帶參數(shù)地址
End If
GetUrl = ScriptAddress & "page="
End Function
'====================================================================
' 設(shè)置 Terminate 事件。
'====================================================================
Private Sub Class_Terminate
XD_RS.close
Set XD_RS=nothing
End Sub
'====================================================================
'ShowError 錯誤提示
'====================================================================
Private Sub ShowError()
If str_Error <> "" Then
Response.Write("
" & SW_Error & "")
Response.End
End If
End Sub
End class
出處
'=====================================================================
'XDOWNPAGE ASP版本
'版本 1.00
'Code by zykj2000
'Email: zykj_2000@163.net
'BBS: http://bbs.513soft.net
'本程序可以免費使用、修改,希望我的程序能為您的工作帶來方便
'但請保留以上請息
'
'程序特點
'本程序主要是對數(shù)據(jù)分頁的部分進(jìn)行了封裝,而數(shù)據(jù)顯示部份完全由用戶自定義,
'支持URL多個參數(shù)
'
'使用說明
'程序參數(shù)說明
'PapgeSize 定義分頁每一頁的記錄數(shù)
'GetRS 返回經(jīng)過分頁的Recordset此屬性只讀
'GetConn 得到數(shù)據(jù)庫連接
'GetSQL 得到查詢語句
'程序方法說明
'ShowPage 顯示分頁導(dǎo)航條,唯一的公用方法
'
'例:
'
' '包含文件
'
' Set mypage=new xdownpage '創(chuàng)建對象
' mypage.getconn=conn '得到數(shù)據(jù)庫連接
' mypage.getsql="select * from productinfo order by id asc"
' mypage.pagesize=5 '設(shè)置每一頁的記錄條數(shù)據(jù)為5條
' set rs=mypage.getrs() '返回Recordset
' mypage.showpage() '顯示分頁信息,這個方法可以,在set rs=mypage.getrs()以后
' 任意位置調(diào)用,可以調(diào)用多次
' for i=1 to mypage.pagesize '接下來的操作就和操作一個普通Recordset對象一樣操作
' if not rs.eof then '這個標(biāo)記是為了防止最后一頁的溢出
' response.write rs(0) & "
" '這里就可以自定義顯示方式了
' rs.movenext
' else
' exit for
' end if
' next
'
'=====================================================================
Const Btn_First="9" '定義第一頁按鈕顯示樣式
Const Btn_Prev="3" '定義前一頁按鈕顯示樣式
Const Btn_Next="4" '定義下一頁按鈕顯示樣式
Const Btn_Last=":" '定義最后一頁按鈕顯示樣式
Const XD_Align="center" '定義分頁信息對齊方式
Const XD_Width="100%" '定義分頁信息框大小
Const XD_Height="20"
Class Xdownpage
Private XD_PageCount,XD_Conn,XD_Rs,XD_SQL,XD_PageSize,Str_errors,int_curpage,str_URL,int_totalPage,int_totalRecord
'=================================================================
'PageSize 屬性
'設(shè)置每一頁的分頁大小
'=================================================================
Public Property Let PageSize(int_PageSize)
If IsNumeric(Int_Pagesize) Then
XD_PageSize=CLng(int_PageSize)
Else
str_error=str_error & "PageSize的參數(shù)不正確"
ShowError()
End If
End Property
Public Property Get PageSize
If XD_PageSize="" or (not(IsNumeric(XD_PageSize))) Then
PageSize=10
Else
PageSize=XD_PageSize
End If
End Property
'=================================================================
'GetRS 屬性
'返回分頁后的記錄集
'=================================================================
Public Property Get GetRs()
Set XD_Rs=Server.createobject("adodb.recordset")
XD_Rs.PageSize=PageSize
XD_Rs.Open XD_SQL,XD_Conn,1,1
If not(XD_Rs.eof and XD_RS.BOF) Then
If int_curpage>XD_RS.PageCount Then
int_curpage=XD_RS.PageCount
End If
XD_Rs.AbsolutePage=int_curpage
End If
Set GetRs=XD_RS
End Property
'================================================================
'GetConn 得到數(shù)據(jù)庫連接
'
'================================================================
Public Property Let GetConn(obj_Conn)
Set XD_Conn=obj_Conn
End Property
'================================================================
'GetSQL 得到查詢語句
'
'================================================================
Public Property Let GetSQL(str_sql)
XD_SQL=str_sql
End Property
'==================================================================
'Class_Initialize 類的初始化
'初始化當(dāng)前頁的值
'
'==================================================================
Private Sub Class_Initialize
'========================
'設(shè)定一些參數(shù)的黙認(rèn)值
'========================
XD_PageSize=10 '設(shè)定分頁的默認(rèn)值為10
'========================
'獲取當(dāng)前面的值
'========================
If request("page")="" Then
int_curpage=1
ElseIf not(IsNumeric(request("page"))) Then
int_curpage=1
ElseIf CInt(Trim(request("page")))<1 Then
int_curpage=1
Else
Int_curpage=CInt(Trim(request("page")))
End If
End Sub
'====================================================================
'ShowPage 創(chuàng)建分頁導(dǎo)航條
'有首頁、前一頁、下一頁、末頁、還有數(shù)字導(dǎo)航
'
'====================================================================
Public Sub ShowPage()
Dim str_tmp
int_totalRecord=XD_RS.RecordCount
If int_totalRecord<=0 Then
str_error=str_error & "總記錄數(shù)為零,請輸入數(shù)據(jù)"
Call ShowError()
End If
If int_totalRecord int_TotalPage=1
Else
If int_totalRecord mod PageSize =0 Then
int_TotalPage = Int(int_TotalRecord / XD_PageSize * -1)*-1
Else
int_TotalPage = Int((int_TotalRecord / XD_PageSize * -1)*-1)+1
End If
End If
If Int_curpage>int_Totalpage Then
int_curpage=int_TotalPage
End If
'===============================================================================
'顯示分頁信息,各個模塊根據(jù)自己要求更改顯求位置
'===============================================================================
response.write " "
str_tmp=ShowFirstPrv
response.write str_tmp
str_tmp=showNumBtn
response.write str_tmp
str_tmp=ShowNextLast
response.write str_tmp
str_tmp=ShowPageInfo
response.write str_tmp
'Response.write " "
ShowGoto
response.write "
"
End Sub
'====================================================================
'ShowFirstPrv 顯示首頁、前一頁
'
'
'====================================================================
Private Function ShowFirstPrv()
Dim Str_tmp,int_prvpage
If int_curpage=1 Then
str_tmp=Btn_First&" "&Btn_Prev
Else
int_prvpage=int_curpage-1
str_tmp=""&Btn_First&" "& Btn_Prev&""
End If
ShowFirstPrv=str_tmp
End Function
'====================================================================
'ShowNextLast 下一頁、末頁
'
'
'====================================================================
Private Function ShowNextLast()
Dim str_tmp,int_Nextpage
If Int_curpage>=int_totalpage Then
str_tmp=Btn_Next & " " & Btn_Last
Else
Int_NextPage=int_curpage+1
str_tmp=""&Btn_Next&" "& Btn_Last&""
End If
ShowNextLast=str_tmp
End Function
'====================================================================
'ShowNumBtn 數(shù)字導(dǎo)航
'
'
'====================================================================
'Private Function showNumBtn()
' Dim i,str_tmp
' For i=1 to int_totalpage
' str_tmp=str_tmp & "["&i&"] "
' Next
' showNumBtn=str_tmp
'
'End Function
'====================================================================
'ShowNumBtn 修改后的數(shù)字導(dǎo)航
'
'====================================================================
Function showNumBtn()
Dim i,str_tmp,end_page,start_page
if int_curpage>4 then
if int_curpage+2 start_page=int_curpage-2
end_page=int_curpage+2
else
start_page=int_totalpage-4
end_page=int_totalpage
end if
else
start_page=1
if int_totalpage>5 then
end_page=5
else
end_page=int_totalpage
end if
end if
For i=start_page to end_page
str_tmp=str_tmp & " ["&i&"] "
Next
showNumBtn=str_tmp
End Function
'====================================================================
'ShowGoto 頁面跳轉(zhuǎn)
'
'
'====================================================================
Private Function ShowGoto()
Dim M_item
'========================================================
'將返回的Url參數(shù)逐個的寫入隱藏域中,以便與參數(shù)繼續(xù)傳遞
'========================================================
For Each M_item In Request.QueryString
If InStr("page",M_Item)=0 Then '從參數(shù)中除去 "page" 的值
Response.Write ""
End If
Next
'========================================================
response.write " 轉(zhuǎn)到第:"
response.write " 頁 "
End Function
'====================================================================
'ShowPageInfo 分頁信息
'更據(jù)要求自行修改
'
'====================================================================
Private Function ShowPageInfo()
Dim str_tmp
str_tmp=" [頁次:"&int_curpage&"/"&int_totalpage&"頁] [共"&int_totalrecord&"條] ["&XD_PageSize&"條/頁]"
ShowPageInfo=str_tmp
End Function
'====================================================================
'修改后的獲取當(dāng)前Url參數(shù)的函數(shù)
'Codeing by Redsun
'====================================================================
Private Function GetUrl()
Dim ScriptAddress, M_ItemUrl, M_item
ScriptAddress = CStr(Request.ServerVariables("SCRIPT_NAME"))&"?"'取得當(dāng)前地址
If (Request.QueryString <> "") Then
M_ItemUrl = ""
For Each M_item In Request.QueryString
If InStr("page",M_Item)=0 Then
M_ItemUrl = M_ItemUrl & M_Item &"="& Server.URLEncode(Request.QueryString(""&M_Item&"")) & "&"
End If
Next
ScriptAddress = ScriptAddress & M_ItemUrl'取得帶參數(shù)地址
End If
GetUrl = ScriptAddress & "page="
End Function
'====================================================================
' 設(shè)置 Terminate 事件。
'====================================================================
Private Sub Class_Terminate
XD_RS.close
Set XD_RS=nothing
End Sub
'====================================================================
'ShowError 錯誤提示
'====================================================================
Private Sub ShowError()
If str_Error <> "" Then
Response.Write("
" & SW_Error & "")
Response.End
End If
End Sub
End class
相關(guān)文章
網(wǎng)上用的比較多的asp級聯(lián)菜單效果代碼
ASP連動下拉列表從數(shù)據(jù)庫讀取2008-04-04ASP自動獲取漢字首字母函數(shù)(支持UTF-8/GB2312)
ASP獲取漢字首字母函數(shù)分享,分GB2312編碼和UTF-8編碼兩種,每次傳入一個漢字或一個字符。(具體如何獲得字符串中的一個字符,就大家自己想啦2007-08-08asp實現(xiàn)批量插入表單中的數(shù)據(jù)到數(shù)據(jù)庫的方法
asp實現(xiàn)批量插入表單中的數(shù)據(jù)到數(shù)據(jù)庫的方法...2007-08-08