1 //------------------------------------------------------------------------------ 2 // <copyright file="TableRow.cs" company="Microsoft"> 3 // Copyright (c) Microsoft Corporation. All rights reserved. 4 // </copyright> 5 //------------------------------------------------------------------------------ 6 7 namespace System.Web.UI.WebControls { 8 9 using System; 10 using System.ComponentModel; 11 using System.Globalization; 12 using System.Web; 13 using System.Web.UI; 14 using System.Web.Util; 15 16 /// <devdoc> 17 /// <para> Encapsulates a row 18 /// within a table.</para> 19 /// </devdoc> 20 [ 21 Bindable(false), 22 DefaultProperty("Cells"), 23 ParseChildren(true, "Cells"), 24 ToolboxItem(false) 25 ] 26 [Designer("System.Web.UI.Design.WebControls.PreviewControlDesigner, " + AssemblyRef.SystemDesign)] 27 public class TableRow : WebControl { 28 29 TableCellCollection cells; 30 31 32 /// <devdoc> 33 /// <para> 34 /// Initializes a new instance of the <see cref='System.Web.UI.WebControls.TableRow'/> class. 35 /// </para> 36 /// </devdoc> TableRow()37 public TableRow() : base(HtmlTextWriterTag.Tr) { 38 PreventAutoID(); 39 } 40 41 42 /// <devdoc> 43 /// <para> Indicates the table cell collection of the table 44 /// row. This property is read-only.</para> 45 /// </devdoc> 46 [ 47 MergableProperty(false), 48 WebSysDescription(SR.TableRow_Cells), 49 PersistenceMode(PersistenceMode.InnerDefaultProperty) 50 ] 51 public virtual TableCellCollection Cells { 52 get { 53 if (cells == null) 54 cells = new TableCellCollection(this); 55 return cells; 56 } 57 } 58 59 60 /// <devdoc> 61 /// <para> Indicates the horizontal alignment of the content within the table cells.</para> 62 /// </devdoc> 63 [ 64 WebCategory("Layout"), 65 DefaultValue(HorizontalAlign.NotSet), 66 WebSysDescription(SR.TableItem_HorizontalAlign) 67 ] 68 public virtual HorizontalAlign HorizontalAlign { 69 get { 70 if (ControlStyleCreated == false) { 71 return HorizontalAlign.NotSet; 72 } 73 return ((TableItemStyle)ControlStyle).HorizontalAlign; 74 } 75 set { 76 ((TableItemStyle)ControlStyle).HorizontalAlign = value; 77 } 78 } 79 80 public override bool SupportsDisabledAttribute { 81 get { 82 return RenderingCompatibility < VersionUtil.Framework40; 83 } 84 } 85 86 [ 87 WebCategory("Accessibility"), 88 DefaultValue(TableRowSection.TableBody), 89 WebSysDescription(SR.TableRow_TableSection) 90 ] 91 public virtual TableRowSection TableSection { 92 get { 93 object o = ViewState["TableSection"]; 94 return((o == null) ? TableRowSection.TableBody : (TableRowSection)o); 95 } 96 set { 97 if (value < TableRowSection.TableHeader || value > TableRowSection.TableFooter) { 98 throw new ArgumentOutOfRangeException("value"); 99 } 100 ViewState["TableSection"] = value; 101 if (value != TableRowSection.TableBody) { 102 Control parent = Parent; 103 if (parent != null) { 104 Table parentTable = parent as Table; 105 if (parentTable != null) { 106 parentTable.HasRowSections = true; 107 } 108 } 109 } 110 } 111 } 112 113 114 /// <devdoc> 115 /// <para>Indicates the vertical alignment of the content within the cell.</para> 116 /// </devdoc> 117 [ 118 WebCategory("Layout"), 119 DefaultValue(VerticalAlign.NotSet), 120 WebSysDescription(SR.TableItem_VerticalAlign) 121 ] 122 public virtual VerticalAlign VerticalAlign { 123 get { 124 if (ControlStyleCreated == false) { 125 return VerticalAlign.NotSet; 126 } 127 return ((TableItemStyle)ControlStyle).VerticalAlign; 128 } 129 set { 130 ((TableItemStyle)ControlStyle).VerticalAlign = value; 131 } 132 } 133 134 135 /// <internalonly/> 136 /// <devdoc> 137 /// <para>A protected method. Creates a table item control style.</para> 138 /// </devdoc> CreateControlStyle()139 protected override Style CreateControlStyle() { 140 return new TableItemStyle(ViewState); 141 } 142 143 144 /// <devdoc> 145 /// <para>[To be supplied.]</para> 146 /// </devdoc> CreateControlCollection()147 protected override ControlCollection CreateControlCollection() { 148 return new CellControlCollection(this); 149 } 150 151 152 /// <devdoc> 153 /// <para>[To be supplied.]</para> 154 /// </devdoc> 155 protected class CellControlCollection : ControlCollection { 156 CellControlCollection(Control owner)157 internal CellControlCollection (Control owner) : base(owner) { 158 } 159 160 161 /// <devdoc> 162 /// <para>Adds the specified <see cref='System.Web.UI.Control'/> object to the collection. The new control is added 163 /// to the end of the array.</para> 164 /// </devdoc> Add(Control child)165 public override void Add(Control child) { 166 if (child is TableCell) 167 base.Add(child); 168 else 169 throw new ArgumentException(SR.GetString(SR.Cannot_Have_Children_Of_Type, "TableRow", child.GetType().Name.ToString(CultureInfo.InvariantCulture))); // throw an exception here 170 } 171 172 173 /// <devdoc> 174 /// <para>Adds the specified <see cref='System.Web.UI.Control'/> object to the collection. The new control is added 175 /// to the array at the specified index location.</para> 176 /// </devdoc> AddAt(int index, Control child)177 public override void AddAt(int index, Control child) { 178 if (child is TableCell) 179 base.AddAt(index, child); 180 else 181 throw new ArgumentException(SR.GetString(SR.Cannot_Have_Children_Of_Type, "TableRow", child.GetType().Name.ToString(CultureInfo.InvariantCulture))); // throw an exception here 182 } 183 } // class CellControlCollection 184 185 } 186 } 187 188