asp高效率通用分頁類

來源:互聯網
上載者:User
效率|分頁類 <%
'=====================================================================
'PapgeSize 定義分頁每一頁的記錄數
'GetRS 返回經過分頁的Recordset此屬性唯讀
'GetConn 得到資料庫連接
'GetSQL 得到查詢語句
'程式方法說明
'ShowPage 顯示分頁導航條,唯一的公用方法
'例:
' Set mypage=new xdownpage '建立對象
' mypage.getconn=conn '得到資料庫連接
' mypage.getsql="select * from productinfo order by id asc"
' mypage.pagesize=5 '設定每一頁的記錄條資料為5條
' set rs=mypage.getrs() '返回Recordset
' mypage.showpage() '顯示分頁資訊,這個方法可以,在set rs=mypage.getrs()以後
' 任意位置調用,可以調用多次
' for i=1 to mypage.pagesize '接下來的操作就和操作一個普通Recordset對象一樣操作
' if not rs.eof then '這個標記是為了防止最後一頁的溢出
' response.write rs(0) & "
' 這裡就可以自訂顯示方式了
' rs.movenext
' else
' exit for
' end if
' next
'=====================================================================
Const Btn_First="<font face=webdings>9</font>" '定義第一頁按鈕顯示樣式
Const Btn_Prev="<font face=webdings>3</font>" '定義前一頁按鈕顯示樣式
Const Btn_Next="<font face=webdings>4</font>" '定義下一頁按鈕顯示樣式
Const Btn_Last="<font face=webdings>:</font>" '定義最後一頁按鈕顯示樣式
Const XD_Align="Right" '定義分頁資訊對齊
Const XD_Width="100%" '定義分頁資訊框大小
Class Xdownpage
Private XD_PageCount,XD_Conn,XD_Rs,XD_SQL,XD_PageSize,Str_errors,int_curpage,str_URL,int_totalPage,int_totalRecord
'=================================================================
'PageSize 屬性
'設定每一頁的分頁大小
'=================================================================
Public Property Let PageSize(int_PageSize)
If IsNumeric(Int_Pagesize) Then
XD_PageSize=CLng(int_PageSize)
Else
str_error=str_error & "PageSize的參數不正確"
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 得到資料庫連接
'================================================================
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 類的初始化
'初始化當前頁的值
'==================================================================
Private Sub Class_Initialize
'========================
'設定一些參數的黙認值
'========================
XD_PageSize=10 '設定分頁的預設值為10
'========================
'擷取當前面的值
'========================
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 建立分頁導航條
'有首頁、前一頁、下一頁、末頁、還有數字導航
'====================================================================
Public Sub ShowPage()
Dim str_tmp
int_totalRecord=XD_RS.RecordCount
If int_totalRecord<=0 Then
str_error=str_error & "總記錄數為零,請輸入資料"
Call ShowError()
End If
If int_totalRecord<pagesize Then
int_TotalPage=1
Else
int_TotalPage=XD_RS.PageCount
'If int_totalRecord mod PageSize =0 Then
' int_TotalPage = CLng(int_TotalRecord / XD_PageSize * -1)*-1
'Else
' int_TotalPage = CLng(int_TotalRecord / XD_PageSize * -1)*-1+1
'End If
End If
If Int_curpage>int_Totalpage Then
int_curpage=int_TotalPage
End If
'===============================================================================
'顯示分頁資訊,各個模組根據自己要求更改顯求位置
'===============================================================================
response.write "<table border=0 width="&XD_Width&"><tr><td align="&XD_Align&">"
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 "</td></tr></table>"
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="<a href="&geturl&"1>"&Btn_First&"</a><a href="&geturl & int_prvpage &">"& Btn_Prev&"</a>"
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="<a href="& geturl & int_NextPage &">"&Btn_Next&"</a><a href="&geturl & int_totalpage &">"& Btn_Last&"</a>"
End If
ShowNextLast=str_tmp
End Function
'====================================================================
'ShowNumBtn 數字導航
'====================================================================
Private Function showNumBtn()
Dim i,str_tmp
For i=1 to int_totalpage
str_tmp=str_tmp & "<a href="& geturl & i &">["&i&"]</a>"
Next
showNumBtn=str_tmp
End Function
'====================================================================
'ShowPageInfo 分頁資訊
'更據要求自行修改
'
'====================================================================
Private Function ShowPageInfo()
Dim str_tmp
str_tmp="頁次:"&int_curpage&"/"&int_totalpage&"頁 共"&int_totalrecord&"條記錄 "&XD_PageSize&"條/每頁"
ShowPageInfo=str_tmp
End Function
'==================================================================
'GetURL 得到當前的URL
'更據URL參數不同,擷取不同的結果
'==================================================================
Private Function GetURL()
Dim strurl,str_url,i,j,search_str,result_url
search_str="page="
strurl=Request.ServerVariables("URL")
Strurl=split(strurl,"/")
i=UBound(strurl,1)
'response.write i
'response.end
str_url=strurl(i)'得到當前頁檔案名稱
str_params=Request.ServerVariables("QUERY_STRING")
If str_params="" Then
result_url=str_url & "?page="
Else
If InstrRev(str_params,search_str)=0 Then
result_url=str_url & "?" & str_params &"&page="
Else
j=InstrRev(str_params,search_str)-2
If j=-1 Then
result_url=str_url & "?page="
Else
str_params=Left(str_params,j)
result_url=str_url & "?" & str_params &"&page="
End If
End If
End If
GetURL=result_url
End Function
Private Sub ShowError()
If str_Error <> "" Then
Response.Write("<font color=""#FF0000""><b>" & SW_Error & "</font>")
Response.End
End If
End Sub
End class
%>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.