HtmlTable.cs 4.1 KB

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