2
0

Table.cs 3.7 KB

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