首页 > 编程 > .NET > 正文

ASP.net 2.0 自定义控件的开发之数据分页 第三章

2024-07-10 13:06:18
字体:
来源:转载
供稿:网友

控件的属性及事件定义


  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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表