HtmlTable.cs 4.0 KB

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