2 // System.Web.UI.WebControls.AutoGeneratedField.cs
5 // Lluis Sanchez Gual (lluis@novell.com)
7 // (C) 2005 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.
32 using System.Collections;
33 using System.Collections.Specialized;
35 using System.ComponentModel;
36 using System.Security.Permissions;
38 namespace System.Web.UI.WebControls {
40 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
41 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
42 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
43 public sealed class AutoGeneratedField : BoundField
45 Type dataType = typeof(string);
47 internal AutoGeneratedField ()
51 public AutoGeneratedField (string dataField)
53 DataField = dataField;
56 internal AutoGeneratedField (AutoGeneratedFieldProperties fieldProperties)
58 DataField = fieldProperties.DataField;
59 DataType = fieldProperties.Type;
60 SortExpression = fieldProperties.Name;
61 HeaderText = fieldProperties.Name;
62 ReadOnly = fieldProperties.IsReadOnly;
66 public Type DataType {
67 get { return dataType; }
68 set { dataType = value; }
71 public override bool ConvertEmptyStringToNull {
73 set { throw new NotSupportedException (); }
76 public override string DataFormatString {
77 get { return string.Empty; }
78 set { throw new NotSupportedException (); }
81 public override bool InsertVisible {
83 set { throw new NotSupportedException (); }
86 [MonoTODO ("Support other data types")]
87 public override void ExtractValuesFromCell (IOrderedDictionary dictionary,
88 DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly)
90 if (dataType == typeof(bool)) {
91 CheckBox box = (CheckBox) cell.Controls [0];
92 dictionary [DataField] = box.Checked;
94 base.ExtractValuesFromCell (dictionary, cell, rowState, includeReadOnly);
98 [MonoTODO ("Support other data types")]
99 protected override void InitializeDataCell (DataControlFieldCell cell, DataControlRowState rowState)
101 bool editable = (rowState & (DataControlRowState.Edit | DataControlRowState.Insert)) != 0;
103 if (dataType == typeof(bool)) {
104 CheckBox box = new CheckBox ();
105 box.Enabled = editable && !ReadOnly;
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);
120 box.Checked = (bool)val;
127 base.OnDataBindField (sender, e);
130 public override void ValidateSupportsCallback ()
134 protected override DataControlField CreateField ()
136 return new AutoGeneratedField ();
139 protected override void CopyProperties (DataControlField newField)
141 base.CopyProperties (newField);
142 AutoGeneratedField field = (AutoGeneratedField) newField;
143 field.DataType = DataType;
147 protected override object GetDesignTimeValue()
149 return base.GetDesignTimeValue ();