易心asp分頁類 v1.0
易心asp分頁類v1.0
<%
class ex_splitpagecls
'==========================================================================
'易心asp分頁類v1.0
'作者:易心 qq:343931221
'個人網站 www.ex123.net www.bo56.com
'演示地址:www.ex123.net/show/page
'轉載請保留此信息
'==========================================================================
dim ex_rs
dim ex_columns'要提取的字段
dim ex_datafrom'數據表名
dim ex_strwhere'記錄篩選條件
dim ex_order'sql排序
dim ex_idcount'記錄總數
dim ex_pagesize'每頁條數
dim ex_pagecount'總頁數
dim ex_ids'獲得本頁要用到的id
dim ex_sql'構造的sql語句
dim ex_page'當前顯示頁碼
dim ex_conn'數據庫聯接對象
dim ex_index'數據庫記錄當前位置
dim ex_id'主鍵字段
private sub class_initialize
set ex_rs=server.createobject("adodb.recordset")
ex_id="id"
ex_pagesize=20
end sub
private sub class_terminate
ex_rs.close
set ex_rs=nothing
end sub
'屬性賦值:
public property let letconn(str)
ex_conn=str
end property
'屬性賦值:sql語句 要查詢的字段 帶select
public property let letcolumns(str)
ex_columns=str
end property
'屬性賦值:sql語句篩選條件部分 帶where
public property let letwhere(str)
ex_strwhere=str
end property
'屬性賦值:sql語句數據表 帶from
public property let letdatafrom(str)
ex_datafrom=str
end property
'屬性賦值:sql語句排序部分 帶order by
public property let letorder(str)
ex_order=str
end property
'屬性賦值:每頁記錄數
public property let letpagesize(str)
ex_pagesize=str
end property
'屬性賦值:當前頁數
public property let letpage(str)
ex_page=str
end property
'屬性賦值:主表主鍵字段
public property let letid(str)
ex_id=str
end property
'屬性:獲得記錄總數
public property get getrscount
getrscount=ex_idcount
end property
'屬性:獲得頁總數
public property get getpagecount
if(ex_idcount>0) then'如果記錄總數=0,則不處理
if(ex_idcount mod ex_pagesize=0)then'如果記錄總數除以每頁條數有余數,則=記錄總數/每頁條數+1
ex_pagecount=int(ex_idcount/ex_pagesize)'獲取總頁數
else
ex_pagecount=int(ex_idcount/ex_pagesize)+1'獲取總頁數
end if
getpagecount=ex_pagecount
else
getpagecount=0
end if
end property
'屬性:獲得當前頁數
public property get getpage
getpage=ex_page
end property
'獲得本頁要用到的id
private sub ids
dim i
ex_sql="select "&ex_id&" "& ex_datafrom &" " &" "&ex_strwhere&" "&ex_order
ex_rs.open ex_sql,ex_conn,1,1
if not ex_rs.eof and not ex_rs.bof then
ex_rs.pagesize =ex_pagesize '每頁顯示記錄數
ex_rs.absolutepage=cint(ex_page)
ex_idcount=ex_rs.recordcount
if ex_page < 1 then ex_page = 1
if ex_page > ex_pagecount then ex_page = ex_pagecount
if ex_pagecount > 0 then ex_rs.absolutepage =ex_page
for i=1 to ex_rs.pagesize
if ex_rs.eof then exit for
if(i=1)then
ex_ids=ex_rs("id")
else
ex_ids=ex_ids &","&ex_rs("id")
end if
ex_rs.movenext
next
end if
ex_rs.close
end sub
'返回本頁要用到的記錄集
public function execute
ids
ex_sql=ex_columns&" "&ex_datafrom&" "&ex_strwhere&" and id in("&ex_ids&") "&ex_order
ex_rs.open ex_sql,ex_conn,1,1
set execute=ex_rs
end function
end class
%>
代碼如下:
<%
class ex_splitpagecls
'==========================================================================
'易心asp分頁類v1.0
'作者:易心 qq:343931221
'個人網站 www.ex123.net www.bo56.com
'演示地址:www.ex123.net/show/page
'轉載請保留此信息
'==========================================================================
dim ex_rs
dim ex_columns'要提取的字段
dim ex_datafrom'數據表名
dim ex_strwhere'記錄篩選條件
dim ex_order'sql排序
dim ex_idcount'記錄總數
dim ex_pagesize'每頁條數
dim ex_pagecount'總頁數
dim ex_ids'獲得本頁要用到的id
dim ex_sql'構造的sql語句
dim ex_page'當前顯示頁碼
dim ex_conn'數據庫聯接對象
dim ex_index'數據庫記錄當前位置
dim ex_id'主鍵字段
private sub class_initialize
set ex_rs=server.createobject("adodb.recordset")
ex_id="id"
ex_pagesize=20
end sub
private sub class_terminate
ex_rs.close
set ex_rs=nothing
end sub
'屬性賦值:
public property let letconn(str)
ex_conn=str
end property
'屬性賦值:sql語句 要查詢的字段 帶select
public property let letcolumns(str)
ex_columns=str
end property
'屬性賦值:sql語句篩選條件部分 帶where
public property let letwhere(str)
ex_strwhere=str
end property
'屬性賦值:sql語句數據表 帶from
public property let letdatafrom(str)
ex_datafrom=str
end property
'屬性賦值:sql語句排序部分 帶order by
public property let letorder(str)
ex_order=str
end property
'屬性賦值:每頁記錄數
public property let letpagesize(str)
ex_pagesize=str
end property
'屬性賦值:當前頁數
public property let letpage(str)
ex_page=str
end property
'屬性賦值:主表主鍵字段
public property let letid(str)
ex_id=str
end property
'屬性:獲得記錄總數
public property get getrscount
getrscount=ex_idcount
end property
'屬性:獲得頁總數
public property get getpagecount
if(ex_idcount>0) then'如果記錄總數=0,則不處理
if(ex_idcount mod ex_pagesize=0)then'如果記錄總數除以每頁條數有余數,則=記錄總數/每頁條數+1
ex_pagecount=int(ex_idcount/ex_pagesize)'獲取總頁數
else
ex_pagecount=int(ex_idcount/ex_pagesize)+1'獲取總頁數
end if
getpagecount=ex_pagecount
else
getpagecount=0
end if
end property
'屬性:獲得當前頁數
public property get getpage
getpage=ex_page
end property
'獲得本頁要用到的id
private sub ids
dim i
ex_sql="select "&ex_id&" "& ex_datafrom &" " &" "&ex_strwhere&" "&ex_order
ex_rs.open ex_sql,ex_conn,1,1
if not ex_rs.eof and not ex_rs.bof then
ex_rs.pagesize =ex_pagesize '每頁顯示記錄數
ex_rs.absolutepage=cint(ex_page)
ex_idcount=ex_rs.recordcount
if ex_page < 1 then ex_page = 1
if ex_page > ex_pagecount then ex_page = ex_pagecount
if ex_pagecount > 0 then ex_rs.absolutepage =ex_page
for i=1 to ex_rs.pagesize
if ex_rs.eof then exit for
if(i=1)then
ex_ids=ex_rs("id")
else
ex_ids=ex_ids &","&ex_rs("id")
end if
ex_rs.movenext
next
end if
ex_rs.close
end sub
'返回本頁要用到的記錄集
public function execute
ids
ex_sql=ex_columns&" "&ex_datafrom&" "&ex_strwhere&" and id in("&ex_ids&") "&ex_order
ex_rs.open ex_sql,ex_conn,1,1
set execute=ex_rs
end function
end class
%>