Table.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. [PersistChildren(false)]
  25. public class Table: WebControl
  26. {
  27. private TableRowCollection rows;
  28. private class TableRowControlCollection : ControlCollection
  29. {
  30. public TableRowControlCollection (Control owner) : base (owner)
  31. {
  32. }
  33. public override void Add (Control child)
  34. {
  35. if (!(child is TableRow))
  36. throw new ArgumentException (HttpRuntime.FormatResourceString (
  37. "Cannot_Have_Children_Of_Type",
  38. "Table",
  39. child.GetType ().Name.ToString ()));
  40. base.Add (child);
  41. }
  42. public override void AddAt(int index, Control child)
  43. {
  44. if (!(child is TableRow))
  45. throw new ArgumentException (HttpRuntime.FormatResourceString (
  46. "Cannot_Have_Children_Of_Type",
  47. "Table",
  48. child.GetType ().Name.ToString ()));
  49. base.AddAt (index, child);
  50. }
  51. }
  52. public Table () : base (HtmlTextWriterTag.Table)
  53. {
  54. }
  55. public virtual string BackImageUrl
  56. {
  57. get {
  58. if (ControlStyleCreated)
  59. return ((TableStyle) ControlStyle).BackImageUrl;
  60. return String.Empty;
  61. }
  62. set { ((TableStyle) ControlStyle).BackImageUrl = value; }
  63. }
  64. public virtual int CellPadding
  65. {
  66. get {
  67. if (ControlStyleCreated)
  68. return ((TableStyle) ControlStyle).CellPadding;
  69. return -1;
  70. }
  71. set { ((TableStyle) ControlStyle).CellPadding = value; }
  72. }
  73. public virtual int CellSpacing
  74. {
  75. get {
  76. if (ControlStyleCreated)
  77. return ((TableStyle) ControlStyle).CellSpacing;
  78. return -1;
  79. }
  80. set { ((TableStyle) ControlStyle).CellSpacing = value; }
  81. }
  82. public virtual GridLines GridLines
  83. {
  84. get {
  85. if (ControlStyleCreated)
  86. return ((TableStyle) ControlStyle).GridLines;
  87. return GridLines.None;
  88. }
  89. set { ((TableStyle) ControlStyle).GridLines = value; }
  90. }
  91. public virtual HorizontalAlign HorizontalAlign
  92. {
  93. get {
  94. if (ControlStyleCreated)
  95. return ((TableStyle) ControlStyle).HorizontalAlign;
  96. return HorizontalAlign.NotSet;
  97. }
  98. set { ((TableStyle) ControlStyle).HorizontalAlign = value; }
  99. }
  100. public virtual TableRowCollection Rows
  101. {
  102. get {
  103. if (rows == null)
  104. rows = new TableRowCollection (this);
  105. return rows;
  106. }
  107. }
  108. protected override void AddAttributesToRender (HtmlTextWriter writer)
  109. {
  110. base.AddAttributesToRender (writer);
  111. if(!BorderColor.IsEmpty)
  112. writer.AddAttribute (HtmlTextWriterAttribute.Bordercolor,
  113. ColorTranslator.ToHtml (BorderColor));
  114. Unit bw = BorderWidth;
  115. if (GridLines == GridLines.None)
  116. bw = Unit.Pixel (0);
  117. else if (bw.IsEmpty || bw.Type == UnitType.Pixel)
  118. bw = Unit.Pixel(1);
  119. writer.AddAttribute (HtmlTextWriterAttribute.Border,
  120. ((int) bw.Value).ToString (NumberFormatInfo.InvariantInfo));
  121. }
  122. protected override ControlCollection CreateControlCollection ()
  123. {
  124. return new TableRowControlCollection (this);
  125. }
  126. protected override Style CreateControlStyle ()
  127. {
  128. return new TableStyle (ViewState);
  129. }
  130. protected override void RenderContents (HtmlTextWriter writer)
  131. {
  132. foreach (TableRow current in Rows)
  133. current.RenderControl (writer);
  134. }
  135. }
  136. }