Table.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. * Namespace: System.Web.UI.WebControls
  3. * Class: Table
  4. *
  5. * Author: Gaurav Vaish
  6. * Maintainer: [email protected]
  7. * Contact: <[email protected]>, <[email protected]>
  8. * Implementation: yes
  9. * Status: 100%
  10. *
  11. * (C) Gaurav Vaish (2002)
  12. */
  13. using System;
  14. using System.Drawing;
  15. using System.Globalization;
  16. using System.Web;
  17. using System.Web.UI;
  18. namespace System.Web.UI.WebControls
  19. {
  20. public class Table: WebControl
  21. {
  22. private TableRowCollection rows;
  23. private class TableRowControlCollection : ControlCollection
  24. {
  25. public TableRowControlCollection(Control owner): base(owner)
  26. {
  27. }
  28. public override void Add(Control child)
  29. {
  30. if(child is TableRow)
  31. {
  32. Add(child);
  33. return;
  34. }
  35. throw new ArgumentException(HttpRuntime.FormatResourceString("Cannot_Have_Children_Of_Type", "Table", child.GetType().Name.ToString()));
  36. }
  37. public override void AddAt(int index, Control child)
  38. {
  39. if(child is TableRow)
  40. {
  41. Add(child);
  42. return;
  43. }
  44. throw new ArgumentException(HttpRuntime.FormatResourceString("Cannot_Have_Children_Of_Type", "Table", child.GetType().Name.ToString()));
  45. }
  46. }
  47. public Table(): base(HtmlTextWriterTag.Table)
  48. {
  49. }
  50. public virtual string BackImageUrl
  51. {
  52. get
  53. {
  54. if(ControlStyleCreated)
  55. return ((TableStyle)ControlStyle).BackImageUrl;
  56. }
  57. set
  58. {
  59. ((TableStyle)ControlStyle).BackImageUrl = value;
  60. }
  61. }
  62. public virtual int CellPadding
  63. {
  64. get
  65. {
  66. if(ControlStyleCreated)
  67. return ((TableStyle)ControlStyle).CellPadding;
  68. }
  69. set
  70. {
  71. ((TableStyle)ControlStyle).CellPadding = value;
  72. }
  73. }
  74. public virtual int CellSpacing
  75. {
  76. get
  77. {
  78. if(ControlStyleCreated)
  79. return ((TableStyle)ControlStyle).CellSpacing;
  80. }
  81. set
  82. {
  83. ((TableStyle)ControlStyle).CellSpacing = value;
  84. }
  85. }
  86. public virtual GridLines GridLines
  87. {
  88. get
  89. {
  90. if(ControlStyleCreated)
  91. return ((TableStyle)ControlStyle).GridLines;
  92. }
  93. set
  94. {
  95. ((TableStyle)ControlStyle).GridLines = value;
  96. }
  97. }
  98. public virtual HorizontalAlign HorizontalAlign
  99. {
  100. get
  101. {
  102. if(ControlStyleCreated)
  103. return ((TableStyle)ControlStyle).HorizontalAlign;
  104. }
  105. set
  106. {
  107. ((TableStyle)ControlStyle).HorizontalAlign = value;
  108. }
  109. }
  110. public virtual TableRowCollection Rows
  111. {
  112. get
  113. {
  114. if(rows == null)
  115. {
  116. rows = new TableRowCollection(this);
  117. }
  118. return rows;
  119. }
  120. }
  121. protected override void AddAttributesToRender(HtmlTextWriter writer): AddAttributesToRender(writer)
  122. {
  123. if(!BorderColor.IsEmpty)
  124. {
  125. writer.AddAttribute(HtmlTextWriterAttribute.Bordercolor, ColorTranslator.ToHtml(BorderColor));
  126. }
  127. Unit bw = BorderWidth;
  128. if(GridLines == GridLines.None)
  129. {
  130. bw = Unit.Pixel(0);
  131. } else if(!bw.IsEmpty && bw.Type == UnitType.Pixel)
  132. {
  133. bw = Unit.Pixel(1);
  134. }
  135. writer.AddAttribute(HtmlTextWriterAttribute.Border, ((int)bw.Value).ToString(NumberFormatInfo.InvariantInfo));
  136. }
  137. protected override ControlCollection CreateControlCollection()
  138. {
  139. return new TableRowControlCollection(this);
  140. }
  141. protected override Style CreateControlStyle()
  142. {
  143. return new TableStyle(ViewState);
  144. }
  145. protected override void RenderContents(HtmlTextWriter writer)
  146. {
  147. foreach(object current in Rows)
  148. {
  149. ((TableRow)current).RenderControl(writer);
  150. }
  151. }
  152. }
  153. }