Table.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. using System.ComponentModel;
  19. namespace System.Web.UI.WebControls
  20. {
  21. [DefaultProperty("Rows")]
  22. //[Designer("??")]
  23. [ParseChildren(true, "Rows")]
  24. public class Table: WebControl
  25. {
  26. private TableRowCollection rows;
  27. private class TableRowControlCollection : ControlCollection
  28. {
  29. public TableRowControlCollection(Control owner): base(owner)
  30. {
  31. }
  32. public override void Add(Control child)
  33. {
  34. if(child is TableRow)
  35. {
  36. Add(child);
  37. return;
  38. }
  39. throw new ArgumentException(HttpRuntime.FormatResourceString("Cannot_Have_Children_Of_Type", "Table", child.GetType().Name.ToString()));
  40. }
  41. public override void AddAt(int index, Control child)
  42. {
  43. if(child is TableRow)
  44. {
  45. Add(child);
  46. return;
  47. }
  48. throw new ArgumentException(HttpRuntime.FormatResourceString("Cannot_Have_Children_Of_Type", "Table", child.GetType().Name.ToString()));
  49. }
  50. }
  51. public Table(): base(HtmlTextWriterTag.Table)
  52. {
  53. }
  54. public virtual string BackImageUrl
  55. {
  56. get
  57. {
  58. if(ControlStyleCreated)
  59. {
  60. return ((TableStyle)ControlStyle).BackImageUrl;
  61. }
  62. return String.Empty;
  63. }
  64. set
  65. {
  66. ((TableStyle)ControlStyle).BackImageUrl = value;
  67. }
  68. }
  69. public virtual int CellPadding
  70. {
  71. get
  72. {
  73. if(ControlStyleCreated)
  74. {
  75. return ((TableStyle)ControlStyle).CellPadding;
  76. }
  77. return -1;
  78. }
  79. set
  80. {
  81. ((TableStyle)ControlStyle).CellPadding = value;
  82. }
  83. }
  84. public virtual int CellSpacing
  85. {
  86. get
  87. {
  88. if(ControlStyleCreated)
  89. {
  90. return ((TableStyle)ControlStyle).CellSpacing;
  91. }
  92. return -1;
  93. }
  94. set
  95. {
  96. ((TableStyle)ControlStyle).CellSpacing = value;
  97. }
  98. }
  99. public virtual GridLines GridLines
  100. {
  101. get
  102. {
  103. if(ControlStyleCreated)
  104. {
  105. return ((TableStyle)ControlStyle).GridLines;
  106. }
  107. return GridLines.None;
  108. }
  109. set
  110. {
  111. ((TableStyle)ControlStyle).GridLines = value;
  112. }
  113. }
  114. public virtual HorizontalAlign HorizontalAlign
  115. {
  116. get
  117. {
  118. if(ControlStyleCreated)
  119. {
  120. return ((TableStyle)ControlStyle).HorizontalAlign;
  121. }
  122. return HorizontalAlign.NotSet;
  123. }
  124. set
  125. {
  126. ((TableStyle)ControlStyle).HorizontalAlign = value;
  127. }
  128. }
  129. public virtual TableRowCollection Rows
  130. {
  131. get
  132. {
  133. if(rows == null)
  134. {
  135. rows = new TableRowCollection(this);
  136. }
  137. return rows;
  138. }
  139. }
  140. protected override void AddAttributesToRender(HtmlTextWriter writer)
  141. {
  142. AddAttributesToRender(writer);
  143. if(!BorderColor.IsEmpty)
  144. {
  145. writer.AddAttribute(HtmlTextWriterAttribute.Bordercolor, ColorTranslator.ToHtml(BorderColor));
  146. }
  147. Unit bw = BorderWidth;
  148. if(GridLines == GridLines.None)
  149. {
  150. bw = Unit.Pixel(0);
  151. } else if(!bw.IsEmpty && bw.Type == UnitType.Pixel)
  152. {
  153. bw = Unit.Pixel(1);
  154. }
  155. writer.AddAttribute(HtmlTextWriterAttribute.Border, ((int)bw.Value).ToString(NumberFormatInfo.InvariantInfo));
  156. }
  157. protected override ControlCollection CreateControlCollection()
  158. {
  159. return new TableRowControlCollection(this);
  160. }
  161. protected override Style CreateControlStyle()
  162. {
  163. return new TableStyle(ViewState);
  164. }
  165. protected override void RenderContents(HtmlTextWriter writer)
  166. {
  167. foreach(object current in Rows)
  168. {
  169. ((TableRow)current).RenderControl(writer);
  170. }
  171. }
  172. }
  173. }