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) { } }
到此,整个grid的封装就算完成了。
如果结合jquerymobile,可以在grid的render函数中,依据jquerymobile的表格标记输出。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Net Core Web Api项目与在NginX下发布的方法
asp.net core3.1 引用的元包dll版本兼容性问题解决方案
IdentityServer4实现.Net Core API接口权限认证(快速入门)
ASP.NET Core MVC通过IViewLocationExpander扩展视图搜索路径的实现
网友评论