2 // System.Web.UI.WebControls.CheckBoxField.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 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
41 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
42 public class CheckBoxField : BoundField
44 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
45 [BrowsableAttribute (false)]
46 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
47 public override bool ApplyFormatInEditMode {
48 get { throw GetNotSupportedPropException ("ApplyFormatInEditMode"); }
49 set { throw GetNotSupportedPropException ("ApplyFormatInEditMode"); }
52 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
53 [BrowsableAttribute (false)]
54 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
55 public override bool ConvertEmptyStringToNull {
56 get { throw GetNotSupportedPropException ("ConvertEmptyStringToNull"); }
57 set { throw GetNotSupportedPropException ("ConvertEmptyStringToNull"); }
60 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
61 [BrowsableAttribute (false)]
62 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
63 public override string DataFormatString {
64 get { throw GetNotSupportedPropException ("DataFormatString"); }
65 set { throw GetNotSupportedPropException ("DataFormatString"); }
68 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
69 [BrowsableAttribute (false)]
70 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
71 public override bool HtmlEncode {
72 get { throw GetNotSupportedPropException ("HtmlEncode"); }
73 set { throw GetNotSupportedPropException ("HtmlEncode"); }
76 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
77 [BrowsableAttribute (false)]
78 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
79 public override string NullDisplayText {
80 get { throw GetNotSupportedPropException ("NullDisplayText"); }
81 set { throw GetNotSupportedPropException ("NullDisplayText"); }
84 protected override bool SupportsHtmlEncode {
88 [LocalizableAttribute (true)]
89 [DefaultValueAttribute ("")]
90 [WebSysDescription ("")]
91 [WebCategoryAttribute ("Appearance")]
92 public virtual string Text {
93 get { return ViewState.GetString ("Text", ""); }
95 ViewState ["Text"] = value;
100 protected override void InitializeDataCell (DataControlFieldCell cell, DataControlRowState rowState)
102 bool editable = IsEditable (rowState);
103 CheckBox box = new CheckBox ();
104 box.Enabled = editable;
106 box.ToolTip = HeaderText;
108 cell.Controls.Add (box);
111 public override void ExtractValuesFromCell (IOrderedDictionary dictionary,
112 DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly)
114 bool editable = IsEditable (rowState);
115 if (editable || includeReadOnly) {
116 CheckBox box = (CheckBox) cell.Controls [0];
117 dictionary [DataField] = box.Checked;
121 protected override void OnDataBindField (object sender, EventArgs e)
124 DataControlFieldCell cell = (DataControlFieldCell) sender;
125 CheckBox box = (CheckBox) cell.Controls [0];
126 object val = GetValue (cell.BindingContainer);
127 if (val != null && val != DBNull.Value)
128 box.Checked = (bool) val;
130 if (string.IsNullOrEmpty (DataField)) {
138 catch (HttpException) {
141 catch (Exception ex) {
142 throw new HttpException (ex.Message, ex);
146 protected override object GetDesignTimeValue ()
151 protected override DataControlField CreateField ()
153 return new CheckBoxField ();
156 protected override void CopyProperties (DataControlField newField)
158 CheckBoxField field = (CheckBoxField) newField;
159 field.DataField = DataField;
160 field.ReadOnly = ReadOnly;