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)]
\r
45 [BrowsableAttribute (false)]
\r
46 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
\r
47 public override bool ConvertEmptyStringToNull {
48 get { throw GetNotSupportedPropException ("ConvertEmptyStringToNull"); }
49 set { throw GetNotSupportedPropException ("ConvertEmptyStringToNull"); }
52 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
\r
53 [BrowsableAttribute (false)]
\r
54 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
\r
55 public override string DataFormatString {
56 get { throw GetNotSupportedPropException ("DataFormatString"); }
57 set { throw GetNotSupportedPropException ("DataFormatString"); }
60 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
\r
61 [BrowsableAttribute (false)]
\r
62 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
\r
63 public override bool HtmlEncode {
64 get { throw GetNotSupportedPropException ("HtmlEncode"); }
65 set { throw GetNotSupportedPropException ("HtmlEncode"); }
68 [EditorBrowsableAttribute (EditorBrowsableState.Never)]
\r
69 [BrowsableAttribute (false)]
\r
70 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
\r
71 public override string NullDisplayText {
72 get { throw GetNotSupportedPropException ("NullDisplayText"); }
73 set { throw GetNotSupportedPropException ("NullDisplayText"); }
76 protected override bool SupportsHtmlEncode {
80 [LocalizableAttribute (true)]
81 [DefaultValueAttribute ("")]
82 [WebSysDescription ("")]
83 [WebCategoryAttribute ("Appearance")]
84 public virtual string Text {
85 get { return ViewState.GetString ("Text", ""); }
87 ViewState ["Text"] = value;
92 protected override void InitializeDataCell (DataControlFieldCell cell, DataControlRowState rowState)
94 bool editable = (rowState & (DataControlRowState.Edit | DataControlRowState.Insert)) != 0;
95 CheckBox box = new CheckBox ();
96 box.Enabled = editable && !ReadOnly;
97 cell.Controls.Add (box);
100 public override void ExtractValuesFromCell (IOrderedDictionary dictionary,
101 DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly)
103 CheckBox box = (CheckBox) cell.Controls [0];
104 dictionary [DataField] = box.Checked;
107 protected override void OnDataBindField (object sender, EventArgs e)
109 DataControlFieldCell cell = (DataControlFieldCell) sender;
110 CheckBox box = (CheckBox) cell.Controls [0];
111 object val = GetValue (cell.BindingContainer);
113 box.Checked = (bool)val;
121 protected override object GetDesignTimeValue ()
126 protected override DataControlField CreateField ()
128 return new CheckBoxField ();
131 protected override void CopyProperties (DataControlField newField)
133 CheckBoxField field = (CheckBoxField) newField;
134 field.DataField = DataField;
135 field.ReadOnly = ReadOnly;