Grid implementation for Asp. Net Server Control Development (3)

Source: Internet
Author: User

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.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.