2 // System.Web.UI.WebControls.AutoGeneratedField.cs
5 // Lluis Sanchez Gual (lluis@novell.com)
7 // (C) 2005-2010 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
32 using System.Collections.Specialized;
34 using System.ComponentModel;
35 using System.Security.Permissions;
37 namespace System.Web.UI.WebControls
39 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
40 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
41 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
42 public sealed class AutoGeneratedField : BoundField
44 Type dataType = typeof(string);
46 internal AutoGeneratedField ()
50 public AutoGeneratedField (string dataField)
52 DataField = dataField;
55 internal AutoGeneratedField (AutoGeneratedFieldProperties fieldProperties)
57 DataField = fieldProperties.DataField;
58 DataType = fieldProperties.Type;
59 SortExpression = fieldProperties.Name;
60 HeaderText = fieldProperties.Name;
61 ReadOnly = fieldProperties.IsReadOnly;
64 public Type DataType {
65 get { return dataType; }
66 set { dataType = value; }
69 public override bool ConvertEmptyStringToNull {
71 set { throw new NotSupportedException (); }
74 public override string DataFormatString {
75 get { return string.Empty; }
76 set { throw new NotSupportedException (); }
79 public override bool InsertVisible {
81 set { throw new NotSupportedException (); }
84 [MonoTODO ("Support other data types")]
85 public override void ExtractValuesFromCell (IOrderedDictionary dictionary,
86 DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly)
88 if (dataType == typeof(bool)) {
89 bool editable = IsEditable (rowState);
90 if (editable || includeReadOnly) {
91 CheckBox box = (CheckBox) cell.Controls [0];
92 dictionary [DataField] = box.Checked;
95 base.ExtractValuesFromCell (dictionary, cell, rowState, includeReadOnly);
99 [MonoTODO ("Support other data types")]
100 protected override void InitializeDataCell (DataControlFieldCell cell, DataControlRowState rowState)
102 if (dataType == typeof(bool)) {
103 bool editable = IsEditable (rowState);
104 CheckBox box = new CheckBox ();
105 box.Enabled = editable;
106 box.ToolTip = HeaderText;
107 cell.Controls.Add (box);
109 base.InitializeDataCell (cell, rowState);
112 [MonoTODO ("Support other data types")]
113 protected override void OnDataBindField (object sender, EventArgs e)
115 DataControlFieldCell cell = (DataControlFieldCell) sender;
116 if (dataType == typeof(bool)) {
117 CheckBox box = (CheckBox) cell.Controls [0];
118 object val = GetValue (cell.BindingContainer);
119 if (val != null && val != DBNull.Value)
120 box.Checked = (bool)val;
122 if (string.IsNullOrEmpty (DataField)) {
131 base.OnDataBindField (sender, e);
134 public override void ValidateSupportsCallback ()
138 protected override DataControlField CreateField ()
140 return new AutoGeneratedField ();
143 protected override void CopyProperties (DataControlField newField)
145 base.CopyProperties (newField);
146 AutoGeneratedField field = (AutoGeneratedField) newField;
147 field.DataType = DataType;
150 protected override object GetDesignTimeValue()
152 return base.GetDesignTimeValue ();