控件的屬性及事件定義
private shared readonly eventibgotopageclick as new object()
private shared readonly eventlbgotopageclick as new object()
private conn as sqlconnection
private _storedprocedurename as string
private _controltodatabind as string
private _gotostyle as stylegoto = stylegoto.linkbutton
private intpagecount as int32 = 0
private intrecordcount as int32 = 0
private intpagesize as int32
private _defaultimageurl as string
private _hoverimageurl as string
private _pressedimageurl as string
private _controltopaginat as control
private labpageinfo as label
private labpageinfotext_01 as label
private labpageinfotext_02 as label
private labpageinfotext_03 as label
private labpageinfotext_04 as label
private txtpagesize as textbox
private txtpageindex as textbox
private ibgotopage as imagebutton
private lbgotopage as linkbutton
private lbfirstpage as linkbutton
private lbprevpage as linkbutton
private lb下一頁:asp.net 2.0 自定義控件的開發之數據分頁 第四章 as linkbutton
private lb上一頁:asp.net 2.0 自定義控件的開發之數據分頁 第二章 as linkbutton
屬性定義#region "屬性定義"
'=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
< _
bindable(true), _
category("pageinfo"), _
defaultvalue(""), _
description("設置頁的信息(例如:當前 100 條記錄...).") _
> _
public property pageinfotext()property pageinfotext() as string
get
ensurechildcontrols()
return labpageinfo.text
end get
set(byval value as string)
ensurechildcontrols()
labpageinfo.text = value
end set
end property
< _
bindable(true), _
category("pageinfo"), _
defaultvalue(""), _
description("設置顯示 每頁 字符.") _
> _
public property pageinfotext_01()property pageinfotext_01() as string
get
ensurechildcontrols()
return labpageinfotext_01.text
end get
set(byval value as string)
ensurechildcontrols()
labpageinfotext_01.text = value
end set
end property
< _
bindable(true), _
category("pageinfo"), _
defaultvalue(""), _
description("設置顯示 條記錄 字符.") _
> _
public property pageinfotext_02()property pageinfotext_02() as string
get
ensurechildcontrols()
return labpageinfotext_02.text
end get
set(byval value as string)
ensurechildcontrols()
labpageinfotext_02.text = value
end set
end property
< _
bindable(true), _
category("pageinfo"), _
defaultvalue(""), _
description("設置顯示 轉到 字符.") _
> _
public property pageinfotext_03()property pageinfotext_03() as string
get
ensurechildcontrols()
return labpageinfotext_03.text
end get
set(byval value as string)
ensurechildcontrols()
labpageinfotext_03.text = value
end set
end property
< _
bindable(true), _
category("pageinfo"), _
defaultvalue(""), _
description("設置顯示 頁 字符.") _
> _
public property pageinfotext_04()property pageinfotext_04() as string
get
ensurechildcontrols()
return labpageinfotext_04.text
end get
set(byval value as string)
ensurechildcontrols()
labpageinfotext_04.text = value
end set
end property
< _
bindable(true), _
category("style"), _
defaultvalue(""), _
description("頁大小 textbox 邊框的寬度.") _
> _
public property textboxborderwidth()property textboxborderwidth() as unit
get
ensurechildcontrols()
return txtpagesize.borderwidth
end get
set(byval value as unit)
ensurechildcontrols()
txtpagesize.borderwidth = value
txtpageindex.borderwidth = value
end set
end property
< _
bindable(true), _
category("style"), _
defaultvalue(""), _
description("頁大小 textbox 邊框的顏色.") _
> _
public property textboxbordercolor()property textboxbordercolor() as system.drawing.color
get
ensurechildcontrols()
return txtpagesize.bordercolor
end get
set(byval value as system.drawing.color)
ensurechildcontrols()
txtpagesize.bordercolor = value
txtpageindex.bordercolor = value
end set
end property
< _
bindable(true), _
category("style"), _
defaultvalue(""), _
description("頁大小 textbox 的skinid.") _
> _
public property textboxskinid()property textboxskinid() as string
get
ensurechildcontrols()
return txtpagesize.skinid
end get
set(byval value as string)
ensurechildcontrols()
txtpagesize.skinid = value
txtpageindex.skinid = value
end set
end property
< _
bindable(true), _
category("style"), _
defaultvalue(""), _
description("設置轉到的的風格.") _
> _
public property gotostyle()property gotostyle() as stylegoto
get
ensurechildcontrols()
return me._gotostyle
end get
set(byval value as stylegoto)
ensurechildcontrols()
me._gotostyle = value
end set
end property
< _
bindable(true), _
category("style"), _
defaultvalue(""), _
description("設置轉到的按鈕默認圖片.") _
> _
public property defaultimageurl()property defaultimageurl() as string
get
ensurechildcontrols()
return ibgotopage.imageurl
end get
set(byval value as string)
ensurechildcontrols()
ibgotopage.imageurl = value
end set
end property
< _
bindable(true), _
category("style"), _
defaultvalue(""), _
description("設置當鼠標指針在按鈕上時顯示的圖片.") _
> _
public property hoverimageurl()property hoverimageurl() as string
get
ensurechildcontrols()
return me._hoverimageurl
end get
set(byval value as string)
ensurechildcontrols()
me._hoverimageurl = value
end set
end property
< _
bindable(true), _
category("style"), _
defaultvalue(""), _
description("設置當鼠標按下時顯示的圖片.") _
> _
public property pressedimageurl()property pressedimageurl() as string
get
ensurechildcontrols()
return me._pressedimageurl
end get
set(byval value as string)
ensurechildcontrols()
me._pressedimageurl = value
end set
end property
< _
bindable(true), _
category("size"), _
defaultvalue(""), _
description("設置 pagesize 文本框寬度.") _
> _
public property pagesizewidth()property pagesizewidth() as unit
get
ensurechildcontrols()
return txtpagesize.width
end get
set(byval value as unit)
ensurechildcontrols()
txtpagesize.width = value
end set
end property
< _
bindable(true), _
category("size"), _
defaultvalue(""), _
description("設置 pageindex 文本框寬度.") _
> _
public property pageindexwidth()property pageindexwidth() as unit
get
ensurechildcontrols()
return txtpageindex.width
end get
set(byval value as unit)
ensurechildcontrols()
txtpageindex.width = value
end set
end property
< _
bindable(true), _
category("size"), _
defaultvalue(""), _
description("設置 轉到 按鈕的寬度.") _
> _
public property ibgotopagewidth()property ibgotopagewidth() as unit
get
ensurechildcontrols()
return ibgotopage.width
end get
set(byval value as unit)
ensurechildcontrols()
ibgotopage.width = value
end set
end property
< _
bindable(true), _
category("size"), _
defaultvalue(""), _
description("設置 轉到 按鈕的高度.") _
> _
public property ibgotopageheight()property ibgotopageheight() as unit
get
ensurechildcontrols()
return ibgotopage.height
end get
set(byval value as unit)
ensurechildcontrols()
ibgotopage.height = value
end set
end property
< _
bindable(true), _
category("text"), _
defaultvalue(""), _
description("設置 轉到 鏈接按鈕的文字.") _
> _
public property lbgotopagetext()property lbgotopagetext() as string
get
ensurechildcontrols()
return lbgotopage.text
end get
set(byval value as string)
ensurechildcontrols()
lbgotopage.text = value
end set
end property
< _
bindable(true), _
category("database"), _
defaultvalue(""), _
description("設置鏈接數據庫的字符串.") _
> _
public property sqlconnection()property sqlconnection() as string
get
ensurechildcontrols()
return viewstate("sqlconnection")
end get
set(byval value as string)
ensurechildcontrols()
viewstate("sqlconnection") = value
end set
end property
< _
bindable(true), _
category("database"), _
defaultvalue(""), _
description("設置表名.") _
> _
public property tablename()property tablename() as string
get
ensurechildcontrols()
return viewstate("tablename")
end get
set(byval value as string)
ensurechildcontrols()
viewstate("tablename") = value
end set
end property
< _
bindable(true), _
category("database"), _
defaultvalue(""), _
description("設置分頁數據的主鍵.") _
> _
public property primarykeyfield()property primarykeyfield() as string
get
ensurechildcontrols()
return viewstate("primarykeyfield")
end get
set(byval value as string)
ensurechildcontrols()
viewstate("primarykeyfield") = value
end set
end property
< _
bindable(true), _
category("database"), _
defaultvalue(""), _
description("設置返回的字段.") _
> _
public property field()property field() as string
get
ensurechildcontrols()
return viewstate("field")
end get
set(byval value as string)
ensurechildcontrols()
viewstate("field") = value
end set
end property
< _
bindable(true), _
category("database"), _
defaultvalue(""), _
description("設置 where 條件.") _
> _
public property where()property where() as string
get
ensurechildcontrols()
return viewstate("where")
end get
set(byval value as string)
ensurechildcontrols()
viewstate("where") = value
end set
end property
< _
browsable(true), _
category("database"), _
defaultvalue(""), _
description("設置排序方式.") _
> _
public property orderby()property orderby() as string
get
ensurechildcontrols()
return viewstate("orderby")
end get
set(byval value as string)
ensurechildcontrols()
viewstate("orderby") = value
end set
end property
< _
bindable(true), _
category("database"), _
defaultvalue(""), _
description("設置分組方式.") _
> _
public property groupby()property groupby() as string
get
ensurechildcontrols()
return viewstate("groupby")
end get
set(byval value as string)
ensurechildcontrols()
viewstate("groupby") = value
end set
end property
< _
bindable(true), _
category("database"), _
defaultvalue(""), _
typeconverter(gettype(controltodatabindconverter)), _
description("設置要分頁的控件.") _
> _
public property controltopaginate()property controltopaginate() as string
get
ensurechildcontrols()
return viewstate("controltopaginate")
end get
set(byval value as string)
ensurechildcontrols()
viewstate("controltopaginate") = value
end set
end property
< _
bindable(true), _
category("database"), _
defaultvalue(1), _
description("設置當前頁.") _
> _
public property currentpageindex()property currentpageindex() as int32
get
ensurechildcontrols()
return viewstate("currentpageindex")
end get
set(byval value as int32)
ensurechildcontrols()
viewstate("currentpageindex") = value
end set
end property
< _
bindable(true), _
category("database"), _
defaultvalue(""), _
description("每頁顯示數據的大小.") _
> _
public property pagesize()property pagesize() as int32
get
ensurechildcontrols()
if not isnumeric(txtpagesize.text) then
txtpagesize.text = 10
else
if cint(txtpagesize.text) < 1 then
txtpagesize.text = 10
end if
end if
return cint(txtpagesize.text)
end get
set(byval value as int32)
ensurechildcontrols()
txtpagesize.text = value
end set
end property
< _
bindable(true), _
category("database"), _
defaultvalue(""), _
description("將要轉到的頁數.") _
> _
public property pageindex()property pageindex() as string
get
ensurechildcontrols()
return txtpageindex.text
end get
set(byval value as string)
ensurechildcontrols()
txtpageindex.text = value
end set
end property
< _
bindable(false), _
category("database"), _
defaultvalue(""), _
typeconverter(gettype(storedprocedurenameconverter)), _
description("選擇存儲過程。") _
> _
public property storedprocedurename()property storedprocedurename() as string
get
return _storedprocedurename
end get
set(byval value as string)
_storedprocedurename = value
end set
end property
< _
bindable(false), _
category("about"), _
defaultvalue(""), _
description("作者:江建 qq:33512603" & vbcrlf & "編程浪子:http://vbcc.126.com") _
> _
public readonly property about()property about() as string
get
return "作者:江建 qq:33512603" & vbcrlf & "編程浪子:http://vbcc.126.com"
end get
end property
<browsable(false)> _
public readonly property pagecount()property pagecount() as int32
get
ensurechildcontrols()
return viewstate("pagecount")
end get
end property
<browsable(false)> _
public readonly property recordcount()property recordcount() as int32
get
ensurechildcontrols()
return viewstate("recordcount")
end get
end property
'=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#end region
事件定義#region "事件定義"
'=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
private sub ibgotopage_click()sub ibgotopage_click(byval sender as object, byval e as imageclickeventargs)
if not isnumeric(pageindex) then
pageindex = currentpageindex
end if
if pageindex < 1 then
pageindex = 1
elseif pageindex > pagecount then
pageindex = pagecount
end if
currentpageindex = pageindex
call databind()
end sub
private sub lbgotopage_click()sub lbgotopage_click(byval source as object, byval e as eventargs)
if not isnumeric(pageindex) then
pageindex = currentpageindex
end if
if pageindex < 1 then
pageindex = 1
elseif pageindex > pagecount then
pageindex = pagecount
end if
currentpageindex = pageindex
call databind()
end sub
private sub lbfirstpage_click()sub lbfirstpage_click(byval source as object, byval e as eventargs)
currentpageindex = 1
call databind()
end sub<, /p>
private sub lbprevpage_click()sub lbprevpage_click(byval source as object, byval e as eventargs)
if currentpageindex > 1 then
currentpageindex -= 1
end if
call databind()
end sub
private sub lb下一頁:asp.net 2.0 自定義控件的開發之數據分頁 第四章_click()sub lb下一頁:asp.net 2.0 自定義控件的開發之數據分頁 第四章_click(byval source as object, byval e as eventargs)
if currentpageindex < pagecount then
currentpageindex += 1
end if
call databind()
end sub
private sub lb上一頁:asp.net 2.0 自定義控件的開發之數據分頁 第二章_click()sub lb上一頁:asp.net 2.0 自定義控件的開發之數據分頁 第二章_click(byval source as object, byval e as eventargs)
currentpageindex = pagecount
call databind()
end sub
'=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#end region
下面的代碼用于控件的下拉列表屬性頁
public class storedprocedurenameconverterclass storedprocedurenameconverter
inherits stringconverter
'存儲過程 有興趣可以添加你自己的存儲過程
'要用下拉列表編輯屬性
public overrides function getstandardvaluessupported()function getstandardvaluessupported(byval context as itypedescriptorcontext) as boolean
return true
end function
'這個override返回下拉列表項。
public overrides function getstandardvalues()function getstandardvalues(byval context as itypedescriptorcontext) as standardvaluescollection
dim stringarray as arraylist = new arraylist()
stringarray.add("sys_quicksortpaging")
stringarray.add("sys_sortdatapager")
return new standardvaluescollection(stringarray)
end function
'return true的話只能選,return flase可選可填
public overrides function getstandardvaluesexclusive()function getstandardvaluesexclusive(byval context as itypedescriptorcontext) as boolean
return true
end function
end class
public class controltodatabindconverterclass controltodatabindconverter
inherits stringconverter
'列出可以綁定的控件
'要用下拉列表編輯屬性
public overrides function getstandardvaluessupported()function getstandardvaluessupported(byval context as itypedescriptorcontext) as boolean
return true
end function
'這個override返回下拉列表項。
public overrides function getstandardvalues()function getstandardvalues(byval context as itypedescriptorcontext) as standardvaluescollection
dim stringarray as arraylist = new arraylist()
dim i as long
dim objcontrol as controlcollection
objcontrol = ctype(context.container.components(0), page).controls
for i = 0 to objcontrol.count - 1
if typeof objcontrol(i) is gridview or typeof objcontrol(i) is datalist then
stringarray.add(objcontrol(i).clientid)
end if
next
return new standardvaluescollection(stringarray)
end function
'return true的話只能選,return false可選可填
public overrides function getstandardvaluesexclusive()function getstandardvaluesexclusive(byval context as itypedescriptorcontext) as boolean
return false
end function
end class
新聞熱點
疑難解答
圖片精選