Inheritance: System.Web.UI.WebControls.BoundField
Example #1
0
        protected override void CopyProperties(DataControlField newField)
        {
            CheckBoxField field = (CheckBoxField)newField;

            field.DataField = DataField;
            field.ReadOnly  = ReadOnly;
            field.Text      = Text;
        }
 private void AddKeysAndBoundFields(IDataSourceViewSchema schema)
 {
     DataControlFieldCollection columns = ((GridView) base.Component).Columns;
     if (schema != null)
     {
         IDataSourceFieldSchema[] fields = schema.GetFields();
         if ((fields != null) && (fields.Length > 0))
         {
             ArrayList list = new ArrayList();
             foreach (IDataSourceFieldSchema schema2 in fields)
             {
                 if (((GridView) base.Component).IsBindableType(schema2.DataType))
                 {
                     BoundField field;
                     if ((schema2.DataType == typeof(bool)) || (schema2.DataType == typeof(bool?)))
                     {
                         field = new CheckBoxField();
                     }
                     else
                     {
                         field = new BoundField();
                     }
                     string name = schema2.Name;
                     if (schema2.PrimaryKey)
                     {
                         list.Add(name);
                     }
                     field.DataField = name;
                     field.HeaderText = name;
                     field.SortExpression = name;
                     field.ReadOnly = schema2.PrimaryKey || schema2.IsReadOnly;
                     field.InsertVisible = !schema2.Identity;
                     columns.Add(field);
                 }
             }
             ((GridView) base.Component).AutoGenerateColumns = false;
             int count = list.Count;
             if (count > 0)
             {
                 string[] array = new string[count];
                 list.CopyTo(array, 0);
                 ((GridView) base.Component).DataKeyNames = array;
             }
         }
     }
 }
Example #3
0
        public void GenerateColumns()
        {
            if (this.AutoGenerateColumns)
            {
                throw new Exception("GridViewEx: AutoGenerateColumns must be set to false.");
            }

            var dataSource = this.GetDataSource() as ObjectDataSource;
            if (null == dataSource)
            {
                return;
            }

            Type dataObjectType = BuildManager.GetType(dataSource.DataObjectTypeName, false);

            if (null != dataObjectType)
            {
                IOrderedEnumerable<PropertyInfo> allProperties =
                    dataObjectType.GetProperties().Where(
                        x =>
                            x.PropertyType.IsPrimitive || x.PropertyType == typeof (string)
                            || x.PropertyType == typeof(DateTime) || x.PropertyType == typeof(DateTime?)).OrderBy(x => x.DeclaringType == dataObjectType);

                foreach (PropertyInfo property in allProperties)
                {
                    bool readOnly = this.ReadOnlyPropertiesList.Contains(property.Name);
                    bool visibility = !this.HiddenPropertiesList.Contains(property.Name);

                    if (property.PropertyType == typeof (bool))
                    {
                        var checkBoxField = new CheckBoxField
                        {
                            DataField = property.Name,
                            HeaderText = property.Name,
                            SortExpression = property.Name,
                            ReadOnly = readOnly,
                            Visible = visibility
                        };

                        this.Columns.Add(checkBoxField);
                    }
                    else
                    {
                        var field = new BoundField
                        {
                            DataField = property.Name,
                            HeaderText = property.Name,
                            SortExpression = property.Name,
                            ReadOnly = readOnly,
                            Visible = visibility
                        };

                        if (this.EditModeDropDownFields.ContainsKey(property.Name))
                        {
                            // TODO: set drop down as edit mode control
                        }

                        this.Columns.Add(field);
                    }

                    if (property.PropertyType == typeof(DateTime) || property.PropertyType == typeof(DateTime?))
                    {
                        var parameter = new Parameter
                        {
                            Type = TypeCode.DateTime,
                            DbType = DbType.Object,
                            Name = property.Name,
                            Direction = ParameterDirection.Input,
                            DefaultValue = null
                        };

                        dataSource.UpdateParameters.Add(parameter);
                    }
                }
            }

            if (this.EnableEdit || this.EnableDelete)
            {
                var cf = new CommandField
                {
                    ShowEditButton = this.EnableEdit,
                    ShowDeleteButton = this.EnableDelete,
                    HeaderText = "Commands"
                };

                this.Columns.Add(cf);
            }

            this.RowEditing += GridViewExRowEditing;
        }
Example #4
0
        private BoundField GetField(IConfigurationElement element)
        {
            if (element.Attributes.ContainsKey("type"))
            {
                string type = element.Attributes["type"].Value.ToString();

                BoundField field;
                switch (type)
                {
                    case "Text":
                        {
                            field = new BoundField();
                            break;
                        }
                    case "Label":
                        {
                            field = new BoundField();
                            field.ReadOnly = true;
                            break;
                        }
                    case "Date":
                        {
                            field = new DateBoundField();
                            break;
                        }
                    case "Number":
                        {
                            field = new NumberBoundField();
                            break;
                        }
                    case "DropDownList":
                        {
                            field = new DropDownListField();
                            break;
                        }
                    case "CheckBox":
                    case "Check":
                        {
                            field = new CheckBoxField();
                            break;
                        }
                    case "Hidden":
                        {
                            field = new BoundField();
                            field.ItemStyle.CssClass = "hidden";
                            break;
                        }
                    default:
                        {
                            throw new ArgumentException("Unknown grid view field type '" + element.Attributes["type"].Value.ToString() + "'");
                        }
                }
                if (!(field is CheckBoxField))
                {
                    field.HtmlEncode = false;
                }
                if (element.Attributes.ContainsKey("DataMember"))
                    field.DataField = element.Attributes["DataMember"].Value.ToString(); ;
                if (element.Attributes.ContainsKey("HeaderText"))
                    field.HeaderText = element.Attributes["HeaderText"].Value.ToString(); ;
                if (element.Attributes.ContainsKey("FormatString"))
                {
                    try
                    {
                        field.DataFormatString = element.Attributes["FormatString"].Value.ToString();
                    }
                    catch
                    {
                    }
                }
                if (field is DropDownListField)
                {
                    if (element.Attributes.ContainsKey("DataTextField"))
                    {
                        ((DropDownListField)field).DataTextField = element.GetAttributeReference("DataTextField").Value.ToString();
                    }
                    if (element.Attributes.ContainsKey("DataValueField"))
                    {
                        ((DropDownListField)field).DataValueField = element.GetAttributeReference("DataValueField").Value.ToString();
                    }
                }
                return field;
            }
            return null;
        }
Example #5
0
		public static void RenderingCheckBoxField (Page p)
		{
			LiteralControl lcb = new LiteralControl (HtmlDiff.BEGIN_TAG);
			LiteralControl lce = new LiteralControl (HtmlDiff.END_TAG);
			GridView grid = new GridView ();
			grid.AutoGenerateColumns = false;
			grid.ShowFooter = true;
			CheckBoxField checkboxfield = new CheckBoxField ();
			checkboxfield.DataField = BOOLFIELD;
			checkboxfield.HeaderText = "HeaderText";
			checkboxfield.FooterText = "FooterText";
			p.Form.Controls.Add (lcb);
			p.Form.Controls.Add (grid);
			p.Form.Controls.Add (lce);
			grid.DataSource = GridViewTest.CreateDataSource ();
			grid.Columns.Add (checkboxfield);
			grid.DataBind ();
		}
		public void CheckBoxField_CopyProperties()
		{
			PokerCheckBoxField field = new PokerCheckBoxField ();
			CheckBoxField copy = new CheckBoxField();
			field.DataField = "test";
			field.Text = "test";
			field.DoCopyProperties (copy);
			Assert.AreEqual ("test", copy.Text, "Text");
			Assert.AreEqual ("test", copy.DataField, "DataField");
		}
		private void LoadGrid()
		{
            DataSet complexListData = BuildComplexListData();

			grdList.Columns.Clear();

			//TODO:   ADDED 7/6/07
			if (_userCanEditComplexList)
			{
				CheckBoxField cbf = new CheckBoxField();
				cbf.DataField = "Selected";
				cbf.HeaderText = "Select";
				cbf.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
				cbf.Text = "";
				cbf.HeaderStyle.Width = Unit.Parse("50px");
				cbf.Visible = true;
				cbf.SortExpression = String.Empty;
				grdList.Columns.Add(cbf);
                CheckBoxColumn = grdList.Columns.Count - 1;
			}

			foreach (Business.ComplexListField field in _complexList.Fields)
			{
				if (field.Summary ?? false)
				{
					BoundField bnf = new BoundField();
					bnf.HeaderText = field.Name;
					bnf.DataField = field.Name.Trim();      //Note - extra spaces play havoc with the table generation.
					grdList.Columns.Add(bnf);
				}
			}

			if (_userCanEditComplexList)
			{
				ButtonField btf = new ButtonField();
				btf.HeaderText = "";
				btf.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
				btf.Text = "Edit";
				btf.ButtonType = ButtonType.Link;
				btf.HeaderStyle.Width = Unit.Parse("60px");
				btf.Visible = true;
				btf.SortExpression = String.Empty;
				grdList.Columns.Add(btf);
                EditColumn = grdList.Columns.Count - 1;

				btf = new ButtonField();
				btf.HeaderText = "";
				btf.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
				btf.Text = "Delete";
				btf.ButtonType = ButtonType.Link;
				btf.HeaderStyle.Width = Unit.Parse("60px");
				btf.Visible = true;
				btf.SortExpression = String.Empty;
				grdList.Columns.Add(btf);
                DeleteColumn = grdList.Columns.Count - 1;
            }

            grdList.DataSource = complexListData;
			grdList.DataBind();
		}
 public override DataControlFieldsEditor.FieldItem[] CreateFields(DataBoundControl control, IDataSourceFieldSchema[] fieldSchemas)
 {
     if (fieldSchemas == null)
     {
         return null;
     }
     ArrayList list = new ArrayList();
     foreach (IDataSourceFieldSchema schema in fieldSchemas)
     {
         if (((control is GridView) && ((GridView) control).IsBindableType(schema.DataType)) || ((control is DetailsView) && ((DetailsView) control).IsBindableType(schema.DataType)))
         {
             BoundField runtimeField = null;
             DataControlFieldsEditor.FieldItem item = null;
             string name = schema.Name;
             if ((schema.DataType == typeof(bool)) || (schema.DataType == typeof(bool?)))
             {
                 runtimeField = new CheckBoxField {
                     HeaderText = name,
                     DataField = name,
                     SortExpression = name
                 };
                 item = new DataControlFieldsEditor.CheckBoxFieldItem(this._fieldsEditor, (CheckBoxField) runtimeField);
             }
             else
             {
                 runtimeField = new BoundField {
                     HeaderText = name,
                     DataField = name,
                     SortExpression = name
                 };
                 item = new DataControlFieldsEditor.BoundFieldItem(this._fieldsEditor, runtimeField);
             }
             if (schema.PrimaryKey)
             {
                 runtimeField.ReadOnly = true;
             }
             if (schema.Identity)
             {
                 runtimeField.InsertVisible = false;
             }
             item.LoadFieldInfo();
             list.Add(item);
         }
     }
     return (DataControlFieldsEditor.FieldItem[]) list.ToArray(typeof(DataControlFieldsEditor.FieldItem));
 }
 public override DataControlFieldsEditor.FieldItem CreateField()
 {
     CheckBoxField runtimeField = new CheckBoxField();
     string name = string.Empty;
     if (this._fieldSchema != null)
     {
         name = this._fieldSchema.Name;
     }
     if (!this._genericCheckBoxField)
     {
         runtimeField.HeaderText = name;
         runtimeField.DataField = name;
         runtimeField.SortExpression = name;
     }
     if (this._fieldSchema != null)
     {
         if (this._fieldSchema.PrimaryKey)
         {
             runtimeField.ReadOnly = true;
         }
         if (this._fieldSchema.Identity)
         {
             runtimeField.InsertVisible = false;
         }
     }
     DataControlFieldsEditor.FieldItem item = new DataControlFieldsEditor.CheckBoxFieldItem(this._fieldsEditor, runtimeField);
     item.LoadFieldInfo();
     return item;
 }
 public CheckBoxFieldItem(DataControlFieldsEditor fieldsEditor, CheckBoxField runtimeField) : base(fieldsEditor, runtimeField, 10)
 {
 }
 protected override DataControlField SaveValues(string headerText)
 {
     CheckBoxField field = new CheckBoxField {
         HeaderText = headerText
     };
     if (base._haveSchema)
     {
         field.DataField = this._dataFieldList.Text;
     }
     else
     {
         field.DataField = this._dataFieldBox.Text;
     }
     field.ReadOnly = this._readOnlyCheckBox.Checked;
     field.SortExpression = field.DataField;
     return field;
 }
Example #12
0
        /// <summary>
        /// 添加自定义列到Grid的Column中
        /// </summary>
        /// <param name="column"></param>
        void AddToGridColumn(GridColumn column)
        {
            FieldType type = column.type;
            switch (type)
            {
                case FieldType.LineNumberField:
                    LineNumberField lnf = new LineNumberField();
                    lnf.IsContinuousArrange = true;
                    lnf.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
                    lnf.HeaderStyle.Width = column.unit;
                    lnf.ItemStyle.Width = column.unit;
                    lnf.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                    this.Columns.Add(lnf);
                    break;
                case FieldType.BoundField:
                    BoundField bf = new BoundField();
                    bf.HeaderText = column.headerName;
                    bf.HeaderStyle.Width = column.unit;
                    bf.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
                    bf.DataField = column.fieldName;
                    bf.ItemStyle.Width = column.unit;
                    bf.ItemStyle.HorizontalAlign = column.hAlign;
                    bf.SortExpression = column.fieldName;
                    this.Columns.Add(bf);
                    break;
                case FieldType.ButtonField:

                    ButtonField btn = new ButtonField();
                    btn.HeaderText = column.headerName;
                    btn.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
                    btn.HeaderStyle.Width = column.unit;
                    btn.HeaderStyle.Wrap = false;
                    btn.ButtonType = column.button;
                    btn.ItemStyle.Width = column.unit;
                    btn.ItemStyle.HorizontalAlign = column.hAlign;
                    if (btn.ButtonType == ButtonType.Image)
                    {
                        btn.ImageUrl = column.fieldName;
                    }
                    else
                    {
                        btn.Text = column.fieldName;
                    }
                    btn.CommandName = column.commandName;
                    this.Columns.Add(btn);
                    break;
                case FieldType.RadioButtonField:
                    RadioButtonField rbf = new RadioButtonField();
                    rbf.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
                    rbf.HeaderStyle.Width = column.unit;
                    rbf.ItemStyle.Width = column.unit;
                    this.Columns.Add(rbf);
                    break;
                case FieldType.CheckBoxExField:
                    CheckBoxExField cbef = new CheckBoxExField();
                    cbef.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
                    cbef.HeaderStyle.Width = column.unit;
                    cbef.ItemStyle.Width = column.unit;
                    cbef.CheckedValue = "1";
                    this.Columns.Add(cbef);
                    break;
                case FieldType.CheckBoxField:
                    CheckBoxField cbf = new CheckBoxField();
                    cbf.HeaderText = column.headerName;
                    cbf.DataField = column.fieldName;
                    cbf.ItemStyle.HorizontalAlign = column.hAlign;
                    this.Columns.Add(cbf);
                    break;
                case FieldType.HyperLinkField:
                    HyperLinkField hf = new HyperLinkField();
                    //hf.Text = column.headerName;
                    hf.HeaderText = column.headerName;
                    if (string.IsNullOrEmpty(column.text))
                    {
                        hf.DataTextField = column.fieldName;
                    }
                    else
                    {
                        hf.Text = column.text;
                    }
                    hf.ItemStyle.HorizontalAlign = column.hAlign;
                    hf.Target = column.target;
                    hf.DataNavigateUrlFields = column.dataNavigateUrlFields;
                    hf.DataNavigateUrlFormatString = column.dataNavigateUrlFormatString;
                    this.Columns.Add(hf);
                    break;
                case FieldType.LinkButtonTemplate:
                    LinkButtonTemplate lbt = column._linkButtonTemplate;
                    TemplateField templateLinkButtonField = new TemplateField();
                    templateLinkButtonField.ItemTemplate = lbt;
                    templateLinkButtonField.HeaderText = column.headerName;
                    templateLinkButtonField.HeaderStyle.Width = templateLinkButtonField.ItemStyle.Width = column.unit;
                    templateLinkButtonField.HeaderStyle.HorizontalAlign = templateLinkButtonField.ItemStyle.HorizontalAlign = column.hAlign;
                    this.Columns.Add(templateLinkButtonField);
                    break;
                case FieldType.DialogButtonTemplate:

                    DialogButtonTemplate dialogButtonTemplate = column._dialogButtonTemplate;
                    TemplateField templateField = new TemplateField();
                    templateField.ItemTemplate = dialogButtonTemplate;
                    templateField.HeaderText = column.headerName;
                    templateField.HeaderStyle.Width = templateField.ItemStyle.Width = column.unit;
                    templateField.HeaderStyle.HorizontalAlign = templateField.ItemStyle.HorizontalAlign = column.hAlign;
                    this.Columns.Add(templateField);

                    break;
                case FieldType.TextBoxTemplate:
                    TextBoxTemplate tb = column._textBoxTemplate;
                    TemplateField ttb = new TemplateField();
                    ttb.ItemTemplate = tb;
                    ttb.HeaderText = column.headerName;
                    ttb.HeaderStyle.Width = ttb.ItemStyle.Width = column.unit;
                    ttb.HeaderStyle.HorizontalAlign = ttb.ItemStyle.HorizontalAlign = column.hAlign;
                    this.Columns.Add(ttb);
                    break;
                case FieldType.ButtonTemplate:
                    ButtonTemplate bt = column._buttonTemplate;
                    TemplateField templateButtonField = new TemplateField();
                    templateButtonField.ItemTemplate = bt;
                    templateButtonField.HeaderText = column.headerName;
                    templateButtonField.HeaderStyle.Width = templateButtonField.ItemStyle.Width = column.unit;
                    templateButtonField.HeaderStyle.HorizontalAlign = templateButtonField.ItemStyle.HorizontalAlign = column.hAlign;
                    this.Columns.Add(templateButtonField);
                    break;
                default:
                    if (column._dataControlField != null)
                    {
                        this.Columns.Add(column._dataControlField);
                    }
                    break;
            }
        }
Example #13
0
        protected override void Page_Init(object sender, EventArgs e)
        {
            #region imposto le colonne della gridview

            #region azione

            var colTemp = new TemplateField();
            colTemp.HeaderText = Etichette.GetItem(Etichette.EtichetteEnum.PageUsersOrdersActionHeaderText, Languages).Valore;
            colTemp.HeaderStyle.Width = new Unit(60);
            colTemp.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            colTemp.Initialize(false, null);
            __GridView_Elenco.Columns.Insert(0, colTemp);

            #endregion

            #region data

            var col = new BoundField();
            col.HeaderText = Etichette.GetItem(Etichette.EtichetteEnum.PageUsersOrdersDataHeaderText, Languages).Valore;
            col.SortExpression = "Data";
            col.DataField = "Data";
            col.DataFormatString = "{0:d}";
            col.HeaderStyle.Width = new Unit(90);
            col.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            __GridView_Elenco.Columns.Insert(1, col);

            #endregion

            #region prezzo

            col = new BoundField();
            col.HeaderText = Etichette.GetItem(Etichette.EtichetteEnum.PageUsersOrdersPriceHeaderText, Languages).Valore;
            col.SortExpression = "Prezzo";
            col.DataField = "Prezzo";
            col.DataFormatString = "{0:C}";
            //col.HeaderStyle.Width = new Unit(80);
            col.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            __GridView_Elenco.Columns.Insert(2, col);

            #endregion

            #region numero oggetti

            col = new BoundField();
            col.HeaderText = Etichette.GetItem(Etichette.EtichetteEnum.PageUsersOrdersNumberItemsHeaderText, Languages).Valore;
            col.SortExpression = "DBOrdiniProdotti.Sum(Quantità)";
            //col.HeaderStyle.Width = new Unit(120);
            col.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            __GridView_Elenco.Columns.Insert(3, col);

            #endregion

            #region pagato

            col = new CheckBoxField();
            col.HeaderText = Etichette.GetItem(Etichette.EtichetteEnum.PageUsersOrdersPaymentHeaderText, Languages).Valore;
            col.DataField = "Pagato";
            col.SortExpression = "Pagato";
            col.HeaderStyle.Width = new Unit(90);
            col.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            __GridView_Elenco.Columns.Insert(4, col);

            #endregion

            #region spedito

            col = new CheckBoxField();
            col.HeaderText = Etichette.GetItem(Etichette.EtichetteEnum.PageUsersOrdersSentHeaderText, Languages).Valore;
            col.DataField = "Evaso";
            col.SortExpression = "Evaso";
            col.HeaderStyle.Width = new Unit(90);
            col.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            __GridView_Elenco.Columns.Insert(5, col);

            #endregion

            #region id

            col = new BoundField();
            col.HeaderText = Etichette.GetItem(Etichette.EtichetteEnum.PageUsersOrdersSentHeaderTextId, Languages).Valore;
            col.SortExpression = "Id";
            col.DataField = "Id";
            col.HeaderStyle.Width = new Unit(50);
            col.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            __GridView_Elenco.Columns.Insert(6, col);

            #endregion

            #endregion
        }
        private void LoadGrid()
        {
            DataSet complexListData = BuildComplexListData();

            grdList.Columns.Clear();
            if (_userCanEditComplexList)
            {
                CheckBoxField cbf = new CheckBoxField();
                cbf.DataField = "Selected";
                cbf.HeaderText = "Select";
                cbf.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                cbf.Text = "";
                cbf.HeaderStyle.Width = Unit.Parse("50px");
                cbf.Visible = true;
                cbf.ReadOnly = true;
                cbf.SortExpression = String.Empty;
                grdList.Columns.Add(cbf);
            }

            foreach (Business.ComplexListField field in _complexList.Fields)
            {
                if (field.Summary ?? false)
                {
                    BoundField bnf = new BoundField();
                    bnf.HeaderText = field.Name;
                    bnf.DataField = field.Name;
                    if (field.FilterTerm.TermType == TermType.Date)
                    {
                        bnf.ItemStyle.Width = Unit.Pixel(120);
                        bnf.HeaderStyle.Width = Unit.Pixel(120);
                        bnf.FooterStyle.Width = Unit.Pixel(120);
                    }
                    grdList.Columns.Add(bnf);
                }
            }

            if (_userCanEditComplexList)
            {
                ButtonField btf = new ButtonField();
                btf.HeaderText = "";
                btf.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                btf.Text = "Edit";
                btf.ButtonType = ButtonType.Link;
                btf.HeaderStyle.Width = Unit.Parse("60px");
                btf.Visible = true;
                btf.SortExpression = String.Empty;
                grdList.Columns.Add(btf);

                btf = new ButtonField();
                btf.HeaderText = "";
                btf.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                btf.Text = "Delete";
                btf.ButtonType = ButtonType.Link;
                btf.HeaderStyle.Width = Unit.Parse("60px");
                btf.Visible = true;
                btf.SortExpression = String.Empty;
                grdList.Columns.Add(btf);
            }
            
            grdList.DataSource = complexListData;
            grdList.DataBind();
        }