当前位置: 移动技术网 > IT编程>开发语言>.net > Asp.Net服务器控件开发的Grid实现(三)

Asp.Net服务器控件开发的Grid实现(三)

2019年05月10日  | 移动技术网IT编程  | 我要评论

hk23,军事中国网,濠江岁月

下面是gridcolumnseditor的实现代码:

gridcolumnseditor.cs

using system;
using system.collections.generic;
using system.componentmodel.design;
using system.linq;
using system.text;
using system.threading.tasks;
using system.web.ui.webcontrols;

namespace aspnetservercontrol
{
    public class gridcolumnseditor : collectioneditor
    {
        private type[] types;

        /// 
        /// 构造函数
        /// 
        /// 控件类型
        public gridcolumnseditor(type type)
            : base(type)
        {
            types = new type[] { 
                typeof(boundfield)
            };
        }

        /// 
        /// 获取此集合编辑器可包含的数据类型
        /// 
        /// 类型集合
        protected override type[] createnewitemtypes()
        {
            return types;
        }
    }
}
gridcolumnseditor继承自collectioneditor,collectioneditor可以给用户提供一个编辑的界面,并集合大部分的数据类型。

在构造函数中gridcolumnseditor(type type)中,只实现了一个boundfield字段,如果需要其他的字段,可以在后面添加。比如

types = new type[] { 
                typeof(boundfield),
		typeof(checkfield)
            };
下面看一下boundfield字段的实现

 /// 
    /// 表格数据绑定列
    /// 
    [toolboxitem(false)]
    [parsechildren(true)]
    [persistchildren(false)]
    public class boundfield : gridcolumn
    {

    }
boundfield继承自gridcolumn类,这里也有一个parsechildren属性,主要是为了嵌套。

下面看一下gridcolumn的实现

using system;
using system.collections.generic;
using system.componentmodel;
using system.linq;
using system.text;
using system.web.ui;

namespace aspnetservercontrol
{
    /// 
    /// 表格列基类(抽象类)
    /// 
    [toolboxitem(false)]
    [parsechildren(true)]
    [persistchildren(false)]
    [defaultproperty("headertext")]
    public class gridcolumn : controlbase
    {
        private string _headertext = string.empty;
        /// 
        /// 标题栏显示的文字
        /// 
        [category(categoryname.options)]
        [defaultvalue("")]
        [description("标题栏显示的文字")]
        public string headertext
        {
            get
            {
                return _headertext;
            }
            set
            {
                _headertext = value;
            }
        }


        private string _datafield = string.empty;
        /// 
        /// 字段名称
        /// 
        [category(categoryname.options)]
        [defaultvalue("")]
        [description("字段名称")]
        public string datafield
        {
            get
            {
                return _datafield;
            }
            set
            {
                _datafield = value;
            }
        }
    }
}
gridcolumn也继承自controlbase,所以gridcolumn其实也是一个控件,只不过我们将其嵌套在了grid中。

在grid中定义columns的属性时,我们用的是gridcolumncollection类,而该类是一个gridcolumn的集合,代码如下。

public class gridcolumncollection : collection
    {
        public gridcolumncollection(controlbase parent)
        {

        }
    }

再看gridcolumn类中,我们定义了headertext和datafield属性,这两个属性就是我们在default.x页面中编辑grid时,给boundfield添加的属性。

到此,整个grid的封装就算完成了。

如果结合jquerymobile,可以在grid的render函数中,依据jquerymobile的表格标记输出。




如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网