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;
65 public Type DataType {
66 get { return dataType; }
67 set { dataType = value; }
70 public override bool ConvertEmptyStringToNull {
72 set { throw new NotSupportedException (); }
75 public override string DataFormatString {
76 get { return string.Empty; }
77 set { throw new NotSupportedException (); }
80 public override bool InsertVisible {
82 set { throw new NotSupportedException (); }
85 [MonoTODO ("Support other data types")]
86 public override void ExtractValuesFromCell (IOrderedDictionary dictionary,
87 DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly)
89 if (dataType == typeof(bool)) {
90 bool editable = IsEditable (rowState);
91 if (editable || includeReadOnly) {
92 CheckBox box = (CheckBox) cell.Controls [0];
93 dictionary [DataField] = box.Checked;
96 base.ExtractValuesFromCell (dictionary, cell, rowState, includeReadOnly);
100 [MonoTODO ("Support other data types")]
101 protected override void InitializeDataCell (DataControlFieldCell cell, DataControlRowState rowState)
103 if (dataType == typeof(bool)) {
104 bool editable = IsEditable (rowState);
105 CheckBox box = new CheckBox ();
106 box.Enabled = editable;
107 box.ToolTip = HeaderText;
108 cell.Controls.Add (box);
110 base.InitializeDataCell (cell, rowState);
113 [MonoTODO ("Support other data types")]
114 protected override void OnDataBindField (object sender, EventArgs e)
116 DataControlFieldCell cell = (DataControlFieldCell) sender;
117 if (dataType == typeof(bool)) {
118 CheckBox box = (CheckBox) cell.Controls [0];
119 object val = GetValue (cell.BindingContainer);
120 if (val != null && val != DBNull.Value)
121 box.Checked = (bool)val;
123 if (string.IsNullOrEmpty (DataField)) {
132 base.OnDataBindField (sender, e);
135 public override void ValidateSupportsCallback ()
139 protected override DataControlField CreateField ()
141 return new AutoGeneratedField ();
144 protected override void CopyProperties (DataControlField newField)
146 base.CopyProperties (newField);
147 AutoGeneratedField field = (AutoGeneratedField) newField;
148 field.DataType = DataType;
151 protected override object GetDesignTimeValue()
153 return base.GetDesignTimeValue ();