HtmlTableRow.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. //
  2. // System.Web.UI.HtmlControls.HtmlTableRow.cs
  3. //
  4. // Author:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System.ComponentModel;
  29. namespace System.Web.UI.HtmlControls {
  30. #if NET_2_0
  31. [ParseChildren (true, "Cells", ChildControlType = typeof(Control))]
  32. #else
  33. [ParseChildren (true, "Cells")]
  34. #endif
  35. public class HtmlTableRow : HtmlContainerControl {
  36. private HtmlTableCellCollection _cells;
  37. public HtmlTableRow ()
  38. : base ("tr")
  39. {
  40. }
  41. [DefaultValue ("")]
  42. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  43. public string Align {
  44. get {
  45. string s = Attributes ["align"];
  46. return (s == null) ? String.Empty : s;
  47. }
  48. set {
  49. if (value == null)
  50. Attributes.Remove ("align");
  51. else
  52. Attributes ["align"] = value;
  53. }
  54. }
  55. [DefaultValue ("")]
  56. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  57. public string BgColor {
  58. get {
  59. string s = Attributes ["bgcolor"];
  60. return (s == null) ? String.Empty : s;
  61. }
  62. set {
  63. if (value == null)
  64. Attributes.Remove ("bgcolor");
  65. else
  66. Attributes ["bgcolor"] = value;
  67. }
  68. }
  69. [DefaultValue ("")]
  70. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  71. public string BorderColor {
  72. get {
  73. string s = Attributes ["bordercolor"];
  74. return (s == null) ? String.Empty : s;
  75. }
  76. set {
  77. if (value == null)
  78. Attributes.Remove ("bordercolor");
  79. else
  80. Attributes ["bordercolor"] = value;
  81. }
  82. }
  83. [Browsable (false)]
  84. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  85. #if NET_2_0
  86. public virtual
  87. #else
  88. public
  89. #endif
  90. HtmlTableCellCollection Cells {
  91. get {
  92. if (_cells == null)
  93. _cells = new HtmlTableCellCollection (this);
  94. return _cells;
  95. }
  96. }
  97. [DefaultValue ("")]
  98. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  99. public string Height {
  100. get {
  101. string s = Attributes ["height"];
  102. return (s == null) ? String.Empty : s;
  103. }
  104. set {
  105. if (value == null)
  106. Attributes.Remove ("height");
  107. else
  108. Attributes ["height"] = value;
  109. }
  110. }
  111. public override string InnerHtml {
  112. get { throw new NotSupportedException (); }
  113. set { throw new NotSupportedException (); }
  114. }
  115. public override string InnerText {
  116. get { throw new NotSupportedException (); }
  117. set { throw new NotSupportedException (); }
  118. }
  119. [DefaultValue ("")]
  120. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  121. public string VAlign {
  122. get {
  123. string s = Attributes ["valign"];
  124. return (s == null) ? String.Empty : s;
  125. }
  126. set {
  127. if (value == null)
  128. Attributes.Remove ("valign");
  129. else
  130. Attributes ["valign"] = value;
  131. }
  132. }
  133. private int Count {
  134. get { return (_cells == null) ? 0 : _cells.Count; }
  135. }
  136. protected override ControlCollection CreateControlCollection ()
  137. {
  138. return new HtmlTableCellControlCollection (this);
  139. }
  140. #if NET_2_0
  141. protected internal
  142. #else
  143. protected
  144. #endif
  145. override void RenderChildren (HtmlTextWriter writer)
  146. {
  147. int n = Count;
  148. if (n > 0) {
  149. writer.Indent++;
  150. for (int i=0; i < n; i++) {
  151. writer.WriteLine ();
  152. _cells [i].RenderControl (writer);
  153. }
  154. writer.Indent--;
  155. writer.WriteLine ();
  156. }
  157. }
  158. protected override void RenderEndTag (HtmlTextWriter writer)
  159. {
  160. if (Count == 0)
  161. writer.WriteLine ();
  162. writer.WriteEndTag (TagName);
  163. if (writer.Indent == 0)
  164. writer.WriteLine ();
  165. }
  166. protected class HtmlTableCellControlCollection : ControlCollection {
  167. internal HtmlTableCellControlCollection (HtmlTableRow owner)
  168. : base (owner)
  169. {
  170. }
  171. public override void Add (Control child)
  172. {
  173. if (child == null)
  174. throw new NullReferenceException ("null");
  175. if (!(child is HtmlTableCell))
  176. throw new ArgumentException ("child", Locale.GetText ("Must be an HtmlTableCell instance."));
  177. base.Add (child);
  178. }
  179. public override void AddAt (int index, Control child)
  180. {
  181. if (child == null)
  182. throw new NullReferenceException ("null");
  183. if (!(child is HtmlTableCell))
  184. throw new ArgumentException ("child", Locale.GetText ("Must be an HtmlTableCell instance."));
  185. base.AddAt (index, child);
  186. }
  187. }
  188. }
  189. }