HtmlTable.cs 4.0 KB

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