1 //------------------------------------------------------------------------------
2 // <copyright file="HtmlTableRow.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
6 
7 namespace System.Web.UI.HtmlControls {
8     using System;
9     using System.Collections;
10     using System.ComponentModel;
11     using System.Globalization;
12     using System.Web;
13     using System.Web.UI;
14     using System.Security.Permissions;
15 
16 
17     /// <devdoc>
18     ///    <para>
19     ///       The <see langword='HtmlTableRow'/>
20     ///       class defines the properties, methods, and events for the HtmlTableRow control.
21     ///       This class allows programmatic access on the server to individual HTML
22     ///       &lt;tr&gt; elements enclosed within an <see cref='System.Web.UI.HtmlControls.HtmlTable'/> control.
23     ///    </para>
24     /// </devdoc>
25     [
26     ParseChildren(true, "Cells")
27     ]
28     public class HtmlTableRow : HtmlContainerControl {
29         HtmlTableCellCollection cells;
30 
31 
HtmlTableRow()32         public HtmlTableRow() : base("tr") {
33         }
34 
35 
36 
37         /// <devdoc>
38         ///    <para>
39         ///       Gets or sets the horizontal alignment of the cells contained in an
40         ///    <see langword='HtmlTableRow'/> control.
41         ///    </para>
42         /// </devdoc>
43         [
44         WebCategory("Layout"),
45         DefaultValue(""),
46         DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
47         ]
48         public string Align {
49             get {
50                 string s = Attributes["align"];
51                 return((s != null) ? s : String.Empty);
52             }
53 
54             set {
55                 Attributes["align"] = MapStringAttributeToString(value);
56             }
57         }
58 
59         /*
60          * Collection of child TableCells.
61          */
62 
63         /// <devdoc>
64         ///    <para>
65         ///       Gets or sets the group of table cells contained within an
66         ///    <see langword='HtmlTableRow'/> control.
67         ///    </para>
68         /// </devdoc>
69         [
70         Browsable(false),
71         DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
72         ]
73         public virtual HtmlTableCellCollection Cells {
74             get {
75                 if (cells == null)
76                     cells = new HtmlTableCellCollection(this);
77 
78                 return cells;
79             }
80         }
81 
82 
83         /// <devdoc>
84         ///    <para>
85         ///       Gets or sets the background color of an <see langword='HtmlTableRow'/>
86         ///       control.
87         ///    </para>
88         /// </devdoc>
89         [
90         WebCategory("Appearance"),
91         DefaultValue(""),
92         DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
93         ]
94         public string BgColor {
95             get {
96                 string s = Attributes["bgcolor"];
97                 return((s != null) ? s : String.Empty);
98             }
99 
100             set {
101                 Attributes["bgcolor"] = MapStringAttributeToString(value);
102             }
103         }
104 
105 
106         /// <devdoc>
107         ///    <para>
108         ///       Gets or sets the border color of an <see langword='HtmlTableRow'/> control.
109         ///    </para>
110         /// </devdoc>
111         [
112         WebCategory("Appearance"),
113         DefaultValue(""),
114         DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
115         ]
116         public string BorderColor {
117             get {
118                 string s = Attributes["bordercolor"];
119                 return((s != null) ? s : String.Empty);
120             }
121 
122             set {
123                 Attributes["bordercolor"] = MapStringAttributeToString(value);
124             }
125         }
126 
127 
128         /// <devdoc>
129         ///    <para>
130         ///       Gets or sets the height of an <see langword='HtmlTableRow'/> control.
131         ///    </para>
132         /// </devdoc>
133         [
134         WebCategory("Layout"),
135         DefaultValue(""),
136         DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
137         ]
138         public string Height {
139             get {
140                 string s = Attributes["height"];
141                 return((s != null) ? s : String.Empty);
142             }
143 
144             set {
145                 Attributes["height"] = MapStringAttributeToString(value);
146             }
147         }
148 
149 
150         /// <devdoc>
151         ///    <para>[To be supplied.]</para>
152         /// </devdoc>
153         public override string InnerHtml {
154             get {
155                 throw new NotSupportedException(SR.GetString(SR.InnerHtml_not_supported, this.GetType().Name));
156             }
157             set {
158                 throw new NotSupportedException(SR.GetString(SR.InnerHtml_not_supported, this.GetType().Name));
159             }
160         }
161 
162 
163         /// <devdoc>
164         ///    <para>[To be supplied.]</para>
165         /// </devdoc>
166         public override string InnerText {
167             get {
168                 throw new NotSupportedException(SR.GetString(SR.InnerText_not_supported, this.GetType().Name));
169             }
170             set {
171                 throw new NotSupportedException(SR.GetString(SR.InnerText_not_supported, this.GetType().Name));
172             }
173         }
174 
175 
176         /// <devdoc>
177         ///    <para>
178         ///       Gets or sets the vertical alignment of of the cells contained in an
179         ///    <see langword='HtmlTableRow'/> control.
180         ///    </para>
181         /// </devdoc>
182         [
183         WebCategory("Layout"),
184         DefaultValue(""),
185         DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
186         ]
187         public string VAlign {
188             get {
189                 string s = Attributes["valign"];
190                 return((s != null) ? s : String.Empty);
191             }
192 
193             set {
194                 Attributes["valign"] = MapStringAttributeToString(value);
195             }
196         }
197 
198 
199         /// <internalonly/>
200         /// <devdoc>
201         /// </devdoc>
RenderChildren(HtmlTextWriter writer)202         protected internal override void RenderChildren(HtmlTextWriter writer) {
203             writer.WriteLine();
204             writer.Indent++;
205             base.RenderChildren(writer);
206 
207             writer.Indent--;
208         }
209 
210 
211         /// <internalonly/>
212         /// <devdoc>
213         /// </devdoc>
RenderEndTag(HtmlTextWriter writer)214         protected override void RenderEndTag(HtmlTextWriter writer) {
215             base.RenderEndTag(writer);
216             writer.WriteLine();
217         }
218 
219 
220         /// <devdoc>
221         ///    <para>[To be supplied.]</para>
222         /// </devdoc>
CreateControlCollection()223         protected override ControlCollection CreateControlCollection() {
224             return new HtmlTableCellControlCollection(this);
225         }
226 
227 
228         /// <devdoc>
229         ///    <para>[To be supplied.]</para>
230         /// </devdoc>
231         protected class HtmlTableCellControlCollection : ControlCollection {
232 
HtmlTableCellControlCollection(Control owner)233             internal HtmlTableCellControlCollection (Control owner) : base(owner) {
234             }
235 
236 
237             /// <devdoc>
238             /// <para>Adds the specified <see cref='System.Web.UI.Control'/> object to the collection. The new control is added
239             ///    to the end of the array.</para>
240             /// </devdoc>
Add(Control child)241             public override void Add(Control child) {
242                 if (child is HtmlTableCell)
243                     base.Add(child);
244                 else
245                     throw new ArgumentException(SR.GetString(SR.Cannot_Have_Children_Of_Type, "HtmlTableRow", child.GetType().Name.ToString(CultureInfo.InvariantCulture))); // throw an exception here
246             }
247 
248 
249             /// <devdoc>
250             /// <para>Adds the specified <see cref='System.Web.UI.Control'/> object to the collection. The new control is added
251             ///    to the array at the specified index location.</para>
252             /// </devdoc>
AddAt(int index, Control child)253             public override void AddAt(int index, Control child) {
254                 if (child is HtmlTableCell)
255                     base.AddAt(index, child);
256                 else
257                     throw new ArgumentException(SR.GetString(SR.Cannot_Have_Children_Of_Type, "HtmlTableRow", child.GetType().Name.ToString(CultureInfo.InvariantCulture))); // throw an exception here
258             }
259         }
260     }
261 }
262