HtmlTable.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /* System.Web.UI.HtmlControls
  2. * Authors
  3. * Leen Toelen ([email protected])
  4. */
  5. using System;
  6. using System.ComponentModel;
  7. using System.Web;
  8. using System.Web.UI;
  9. using System.Globalization;
  10. namespace System.Web.UI.HtmlControls{
  11. [ParseChildren(true, "Rows")]
  12. public class HtmlTable : HtmlContainerControl {
  13. private HtmlTableRowCollection _rows;
  14. public HtmlTable():base("table"){}
  15. protected override ControlCollection CreateControlCollection(){
  16. return new HtmlTableRowControlCollection(this);
  17. }
  18. protected override void RenderChildren(HtmlTextWriter writer){
  19. writer.WriteLine();
  20. writer.Indent = writer.Indent + 1;
  21. base.RenderChildren(writer);
  22. writer.Indent = writer.Indent - 1;
  23. }
  24. protected override void RenderEndTag(HtmlTextWriter writer){
  25. base.RenderEndTag(writer);
  26. writer.WriteLine();
  27. }
  28. [DefaultValue("")]
  29. [WebCategory("Layout")]
  30. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  31. public string Align {
  32. get{
  33. string attr = Attributes["align"];
  34. if (attr != null) return attr;
  35. return String.Empty;
  36. }
  37. set{
  38. Attributes["align"] = AttributeToString(value);
  39. }
  40. }
  41. [DefaultValue("")]
  42. [WebCategory("Appearance")]
  43. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  44. public string BgColor {
  45. get{
  46. string attr = Attributes["bgcolor"];
  47. if (attr != null) return attr;
  48. return String.Empty;
  49. }
  50. set{
  51. Attributes["bgcolor"] = AttributeToString(value);
  52. }
  53. }
  54. [DefaultValue(-1)]
  55. [WebCategory("Appearance")]
  56. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  57. public int Border {
  58. get{
  59. string attr = Attributes["border"];
  60. if (attr != null) return Int32.Parse(attr, CultureInfo.InvariantCulture);
  61. return -1;
  62. }
  63. set{
  64. Attributes["border"] = AttributeToString(value);
  65. }
  66. }
  67. [DefaultValue("")]
  68. [WebCategory("Appearance")]
  69. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  70. public string BorderColor {
  71. get{
  72. string attr = Attributes["bordercolor"];
  73. if (attr != null) return attr;
  74. return String.Empty;
  75. }
  76. set{
  77. Attributes["bordercolor"] = AttributeToString(value);
  78. }
  79. }
  80. [DefaultValue("")]
  81. [WebCategory("Appearance")]
  82. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  83. public int CellPadding {
  84. get{
  85. string attr = Attributes["cellpadding"];
  86. if (attr != null) return Int32.Parse(attr, CultureInfo.InvariantCulture);
  87. return -1;
  88. }
  89. set{
  90. Attributes["cellpadding"] = AttributeToString(value);
  91. }
  92. }
  93. [DefaultValue("")]
  94. [WebCategory("Appearance")]
  95. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  96. public int CellSpacing {
  97. get{
  98. string attr = Attributes["cellspacing"];
  99. if (attr != null) return Int32.Parse(attr, CultureInfo.InvariantCulture);
  100. return -1;
  101. }
  102. set{
  103. Attributes["cellspacing"] = AttributeToString(value);
  104. }
  105. }
  106. [DefaultValue("")]
  107. [WebCategory("Layout")]
  108. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  109. public string Height {
  110. get{
  111. string attr = Attributes["height"];
  112. if (attr != null) return attr;
  113. return String.Empty;
  114. }
  115. set{
  116. Attributes["height"] = AttributeToString(value);
  117. }
  118. }
  119. public override string InnerHtml {
  120. get{
  121. throw new NotSupportedException("InnerHtml property not supported by HtmlTable");
  122. }
  123. set{
  124. throw new NotSupportedException("InnerHtml property not supported by HtmlTable");
  125. }
  126. }
  127. public override string InnerText {
  128. get{
  129. throw new NotSupportedException("InnerText property not supported by HtmlTable");
  130. }
  131. set{
  132. throw new NotSupportedException("InnerText property not supported by HtmlTable");
  133. }
  134. }
  135. [Browsable(false)]
  136. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  137. public virtual HtmlTableRowCollection Rows {
  138. get{
  139. if (_rows == null) _rows = new HtmlTableRowCollection(this);
  140. return _rows;
  141. }
  142. }
  143. [DefaultValue("")]
  144. [WebCategory("Layout")]
  145. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  146. public string Width {
  147. get{
  148. string attr = Attributes["width"];
  149. if (attr != null) return attr;
  150. return String.Empty;
  151. }
  152. set{
  153. Attributes["width"] = AttributeToString(value);
  154. }
  155. }
  156. protected class HtmlTableRowControlCollection : ControlCollection {
  157. internal HtmlTableRowControlCollection(Control owner): base(owner){}
  158. public override void Add(Control child){
  159. if ((child as HtmlTableRow) != null){
  160. base.Add(child);
  161. }
  162. else{
  163. throw new ArgumentException("HtmlTableRow cannot have children of type " + child.GetType().Name);
  164. }
  165. }
  166. public override void AddAt(int index, Control child){
  167. if ((child as HtmlTableRow) != null){
  168. base.AddAt(index,child);
  169. }
  170. else{
  171. throw new ArgumentException("HtmlTableRow cannot have children of type " + child.GetType().Name);
  172. }
  173. }
  174. } // end of HtmlTableRowControlCollection
  175. }
  176. // end of System.Web.UI.HtmlControl
  177. }