Grid implementation for Asp. Net Server Control Development (3)
The following is the implementation code of 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 ;////// Constructor //////Control TypePublic GridColumnsEditor (Type type): base (type) {types = new Type [] {typeof (BoundField )};}////// Obtain the data types that can be included in the Set editor //////
Type set
Protected override Type [] CreateNewItemTypes () {return types ;}}}
GridColumnsEditor is inherited from CollectionEditor. CollectionEditor provides you with an editing interface and a collection of most data types.
In the GridColumnsEditor (Type type) of the constructor, only one BoundField is implemented. If you need other fields, you can add them later. For example
types = new Type[] { typeof(BoundField),typeof(CheckField) };
The following describes the implementation of the BoundField field.
////// Table data binding column ///[ToolboxItem (false)] [ParseChildren (true)] [PersistChildren (false)] public class BoundField: GridColumn {}
BoundField inherits from the GridColumn class. Here there is also a ParseChildren attribute, mainly for nesting.
The following describes the implementation of GridColumn.
Using System; using System. Collections. Generic; using System. ComponentModel; using System. Linq; using System. Text; using System. Web. UI; namespace AspNetServerControl {////// Table column base class (abstract class )///[ToolboxItem (false)] [ParseChildren (true)] [PersistChildren (false)] [DefaultProperty ("HeaderText")] public class GridColumn: ControlBase {private string _ headerText = String. empty ;////// Text displayed in the title bar ///[Category (CategoryName. OPTIONS)] [DefaultValue ("")] [Description ("text displayed in the title bar")] public string HeaderText {get {return _ headerText ;} set {_ headerText = value ;}} private string _ dataField = String. empty ;////// Field name ///[Category (CategoryName. OPTIONS)] [DefaultValue ("")] [Description ("field name")] public string DataField {get {return _ dataField ;} set {_ dataField = value ;}}}}
GridColumn also inherits from ControlBase, so GridColumn is actually a control, but we nested it in the Grid.
When defining Columns attributes in a Grid, we use the GridColumnCollection class, which is a set of GridColumn. The Code is as follows.
public class GridColumnCollection : Collection
{ public GridColumnCollection(ControlBase parent) { } }
In the GridColumn class, we define the HeaderText and DataField attributes. These two attributes are the attributes added to BoundField when we edit the Grid on the default. aspx page.
By now, the entire Grid Encapsulation is complete.
If jquerymobile is used in combination, you can output the result based on the jquerymobile table tag in the Render function of Grid.