TableCell.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * Namespace: System.Web.UI.WebControls
  3. * Class: TableCell
  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.Globalization;
  15. using System.Web;
  16. using System.Web.UI;
  17. using System.ComponentModel;
  18. namespace System.Web.UI.WebControls
  19. {
  20. [DefaultProperty("Text")]
  21. [ToolboxItem(false)]
  22. [ControlBuilder(typeof(TableCellControlBuilder))]
  23. [ParseChildren(false)]
  24. [PersistChildren(true)]
  25. public class TableCell: WebControl
  26. {
  27. public TableCell () : base (HtmlTextWriterTag.Td)
  28. {
  29. PreventAutoID ();
  30. }
  31. internal TableCell (HtmlTextWriterTag tag) : base (tag)
  32. {
  33. PreventAutoID ();
  34. }
  35. public virtual int ColumnSpan
  36. {
  37. get {
  38. object o = ViewState ["ColumnSpan"];
  39. return (o == null) ? 0 : (int) o;
  40. }
  41. set { ViewState ["ColumnSpan"] = value; }
  42. }
  43. public virtual int RowSpan
  44. {
  45. get {
  46. object o = ViewState ["RowSpan"];
  47. return (o == null) ? 0 : (int) o;
  48. }
  49. set { ViewState ["RowSpan"] = value; }
  50. }
  51. public virtual string Text
  52. {
  53. get {
  54. object o = ViewState ["Text"];
  55. return (o == null) ? String.Empty : (string) o;
  56. }
  57. set { ViewState ["Text"] = value; }
  58. }
  59. public virtual HorizontalAlign HorizontalAlign
  60. {
  61. get {
  62. if (ControlStyleCreated)
  63. return ((TableItemStyle) ControlStyle).HorizontalAlign;
  64. return HorizontalAlign.NotSet;
  65. }
  66. set { ((TableItemStyle) ControlStyle).HorizontalAlign = value; }
  67. }
  68. public virtual VerticalAlign VerticalAlign
  69. {
  70. get {
  71. if (ControlStyleCreated)
  72. return ((TableItemStyle) ControlStyle).VerticalAlign;
  73. return VerticalAlign.NotSet;
  74. }
  75. set { ((TableItemStyle) ControlStyle).VerticalAlign = value; }
  76. }
  77. public virtual bool Wrap
  78. {
  79. get {
  80. if (ControlStyleCreated)
  81. return ((TableItemStyle) ControlStyle).Wrap;
  82. return true;
  83. }
  84. set { ((TableItemStyle) ControlStyle).Wrap = value; }
  85. }
  86. protected override void AddAttributesToRender (HtmlTextWriter writer)
  87. {
  88. base.AddAttributesToRender (writer);
  89. if (ColumnSpan > 0)
  90. writer.AddAttribute (HtmlTextWriterAttribute.Colspan,
  91. ColumnSpan.ToString (NumberFormatInfo.InvariantInfo));
  92. if (RowSpan > 0)
  93. writer.AddAttribute (HtmlTextWriterAttribute.Rowspan,
  94. RowSpan.ToString (NumberFormatInfo.InvariantInfo));
  95. }
  96. protected override void AddParsedSubObject (object obj)
  97. {
  98. if (HasControls ()){
  99. base.AddParsedSubObject (obj);
  100. return;
  101. }
  102. if (obj is LiteralControl){
  103. Text = ((LiteralControl) obj).Text;
  104. return;
  105. }
  106. string text = Text;
  107. if (text.Length > 0){
  108. Text = String.Empty;
  109. base.AddParsedSubObject (new LiteralControl (text));
  110. }
  111. base.AddParsedSubObject (obj);
  112. }
  113. protected override Style CreateControlStyle ()
  114. {
  115. return new TableItemStyle (ViewState);
  116. }
  117. protected override void RenderContents (HtmlTextWriter writer)
  118. {
  119. if (HasControls ())
  120. base.RenderContents (writer);
  121. else
  122. writer.Write (Text);
  123. }
  124. }
  125. }