AutoGeneratedField.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // System.Web.UI.WebControls.AutoGeneratedField.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. [EditorBrowsableAttribute (EditorBrowsableState.Never)]
  37. [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  38. [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  39. public sealed class AutoGeneratedField : BoundField
  40. {
  41. Type dataType = typeof(string);
  42. internal AutoGeneratedField ()
  43. {
  44. }
  45. public AutoGeneratedField (string dataField)
  46. {
  47. DataField = dataField;
  48. }
  49. internal AutoGeneratedField (AutoGeneratedFieldProperties fieldProperties)
  50. {
  51. DataField = fieldProperties.DataField;
  52. SortExpression = fieldProperties.DataField;
  53. DataType = fieldProperties.Type;
  54. HeaderText = fieldProperties.Name;
  55. ReadOnly = fieldProperties.IsReadOnly;
  56. }
  57. [MonoTODO]
  58. public Type DataType {
  59. get { return dataType; }
  60. set { dataType = value; }
  61. }
  62. public override bool ConvertEmptyStringToNull {
  63. get { return true; }
  64. set { throw new NotSupportedException (); }
  65. }
  66. public override string DataFormatString {
  67. get { return string.Empty; }
  68. set { throw new NotSupportedException (); }
  69. }
  70. public override bool InsertVisible {
  71. get { return true; }
  72. set { throw new NotSupportedException (); }
  73. }
  74. [MonoTODO ("Support other data types")]
  75. public override void ExtractValuesFromCell (IOrderedDictionary dictionary,
  76. DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly)
  77. {
  78. if (dataType == typeof(bool)) {
  79. CheckBox box = (CheckBox) cell.Controls [0];
  80. dictionary [DataField] = box.Checked;
  81. } else
  82. base.ExtractValuesFromCell (dictionary, cell, rowState, includeReadOnly);
  83. }
  84. [MonoTODO ("Support other data types")]
  85. protected override void InitializeDataCell (DataControlFieldCell cell, DataControlRowState rowState)
  86. {
  87. bool editable = (rowState & (DataControlRowState.Edit | DataControlRowState.Insert)) != 0;
  88. if (dataType == typeof(bool)) {
  89. CheckBox box = new CheckBox ();
  90. box.Enabled = editable && !ReadOnly;
  91. cell.Controls.Add (box);
  92. } else
  93. base.InitializeDataCell (cell, rowState);
  94. }
  95. [MonoTODO ("Support other data types")]
  96. protected override void OnDataBindField (object sender, EventArgs e)
  97. {
  98. DataControlFieldCell cell = (DataControlFieldCell) sender;
  99. if (dataType == typeof(bool)) {
  100. CheckBox box = (CheckBox) cell.Controls [0];
  101. object val = GetValue (cell.BindingContainer);
  102. if (val != null) {
  103. box.Checked = (bool)val;
  104. if (!box.Visible)
  105. box.Visible = true;
  106. }
  107. else
  108. box.Visible = false;
  109. } else
  110. base.OnDataBindField (sender, e);
  111. }
  112. public override void ValidateSupportsCallback ()
  113. {
  114. }
  115. protected override DataControlField CreateField ()
  116. {
  117. return new AutoGeneratedField ();
  118. }
  119. protected override void CopyProperties (DataControlField newField)
  120. {
  121. base.CopyProperties (newField);
  122. AutoGeneratedField field = (AutoGeneratedField) newField;
  123. field.DataType = DataType;
  124. }
  125. [MonoTODO]
  126. protected override object GetDesignTimeValue()
  127. {
  128. return base.GetDesignTimeValue ();
  129. }
  130. }
  131. }
  132. #endif