CheckBoxField.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // System.Web.UI.WebControls.CheckBoxField.cs
  3. //
  4. // Authors:
  5. // Lluis Sanchez Gual ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0
  30. using System.Collections;
  31. using System.Collections.Specialized;
  32. using System.Web.UI;
  33. using System.ComponentModel;
  34. using System.Security.Permissions;
  35. namespace System.Web.UI.WebControls {
  36. [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  37. [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  38. public class CheckBoxField : BoundField
  39. {
  40. public override bool ConvertEmptyStringToNull {
  41. get { throw GetNotSupportedPropException ("ConvertEmptyStringToNull"); }
  42. set { throw GetNotSupportedPropException ("ConvertEmptyStringToNull"); }
  43. }
  44. public override string DataFormatString {
  45. get { throw GetNotSupportedPropException ("DataFormatString"); }
  46. set { throw GetNotSupportedPropException ("DataFormatString"); }
  47. }
  48. public override bool HtmlEncode {
  49. get { throw GetNotSupportedPropException ("HtmlEncode"); }
  50. set { throw GetNotSupportedPropException ("HtmlEncode"); }
  51. }
  52. public override string NullDisplayText {
  53. get { throw GetNotSupportedPropException ("NullDisplayText"); }
  54. set { throw GetNotSupportedPropException ("NullDisplayText"); }
  55. }
  56. protected override bool SupportsHtmlEncode {
  57. get { return false; }
  58. }
  59. [WebCategoryAttribute ("Appearance")]
  60. [LocalizableAttribute (true)]
  61. [DefaultValueAttribute ("")]
  62. public virtual string Text {
  63. get {
  64. object ob = ViewState ["Text"];
  65. if (ob != null) return (string) ob;
  66. return "";
  67. }
  68. set {
  69. ViewState ["Text"] = value;
  70. OnFieldChanged ();
  71. }
  72. }
  73. public override void InitializeDataCell (DataControlFieldCell cell, DataControlRowState rowState)
  74. {
  75. bool editable = (rowState & DataControlRowState.Edit) != 0;
  76. CheckBox box = new CheckBox ();
  77. box.Enabled = editable && !ReadOnly;
  78. cell.Controls.Add (box);
  79. }
  80. public override void ExtractValuesFromCell (IOrderedDictionary dictionary,
  81. DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly)
  82. {
  83. CheckBox box = (CheckBox) cell.Controls [0];
  84. dictionary [DataField] = box.Checked;
  85. }
  86. protected override void OnDataBindField (object sender, EventArgs e)
  87. {
  88. DataControlFieldCell cell = (DataControlFieldCell) sender;
  89. CheckBox box = (CheckBox) cell.Controls [0];
  90. object val = GetValue (cell.BindingContainer);
  91. if (val != null) {
  92. box.Checked = (bool)val;
  93. if (!box.Visible)
  94. box.Visible = true;
  95. }
  96. else
  97. box.Visible = false;
  98. }
  99. protected override object GetDesignTimeValue ()
  100. {
  101. return true;
  102. }
  103. }
  104. }
  105. #endif