1 //------------------------------------------------------------------------------
2 // <copyright file="HtmlTable.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.Reflection;
10     using System.Collections;
11     using System.ComponentModel;
12     using System.Globalization;
13     using System.Web;
14     using System.Web.UI;
15     using System.Security.Permissions;
16 
17 
18 
19     /// <devdoc>
20     ///    <para>Defines the properties, methods, and events for the
21     ///    <see cref='System.Web.UI.HtmlControls.HtmlTable'/>
22     ///    control that allows programmatic access on the
23     ///    server to the HTML &lt;table&gt; element.</para>
24     /// </devdoc>
25     [
26     ParseChildren(true, "Rows")
27     ]
28     public class HtmlTable : HtmlContainerControl {
29         HtmlTableRowCollection rows;
30 
31 
32         /// <devdoc>
33         ///    Initializes a new instance of the <see cref='System.Web.UI.HtmlControls.HtmlTable'/> class.
34         /// </devdoc>
HtmlTable()35         public HtmlTable() : base("table") {
36         }
37 
38 
39         /// <devdoc>
40         /// <para>Gets or sets the alignment of content within the <see cref='System.Web.UI.HtmlControls.HtmlTable'/>
41         /// control.</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         /// <devdoc>
61         /// <para>Gets or sets the background color of an <see cref='System.Web.UI.HtmlControls.HtmlTable'/>
62         /// control.</para>
63         /// </devdoc>
64         [
65         WebCategory("Appearance"),
66         DefaultValue(""),
67         DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
68         ]
69         public string BgColor {
70             get {
71                 string s = Attributes["bgcolor"];
72                 return((s != null) ? s : String.Empty);
73             }
74 
75             set {
76                 Attributes["bgcolor"] = MapStringAttributeToString(value);
77             }
78         }
79 
80 
81         /// <devdoc>
82         ///    <para>Gets or sets the width of the border, in pixels, of an
83         ///    <see cref='System.Web.UI.HtmlControls.HtmlTable'/> control.</para>
84         /// </devdoc>
85         [
86         WebCategory("Appearance"),
87         DefaultValue(-1),
88         DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
89         ]
90         public int Border {
91             get {
92                 string s = Attributes["border"];
93                 return((s != null) ? Int32.Parse(s, CultureInfo.InvariantCulture) : -1);
94             }
95 
96             set {
97                 Attributes["border"] = MapIntegerAttributeToString(value);
98             }
99         }
100 
101 
102         /// <devdoc>
103         /// <para>Gets or sets the border color of an <see cref='System.Web.UI.HtmlControls.HtmlTable'/> control.</para>
104         /// </devdoc>
105         [
106         WebCategory("Appearance"),
107         DefaultValue(""),
108         DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
109         ]
110         public string BorderColor {
111             get {
112                 string s = Attributes["bordercolor"];
113                 return((s != null) ? s : String.Empty);
114             }
115 
116             set {
117                 Attributes["bordercolor"] = MapStringAttributeToString(value);
118             }
119         }
120 
121 
122         /// <devdoc>
123         ///    <para>
124         ///       Gets or sets the cell padding, in pixels, for an <see langword='HtmlTable'/> control.
125         ///    </para>
126         /// </devdoc>
127         [
128         WebCategory("Appearance"),
129         DefaultValue(""),
130         DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
131         ]
132         public int CellPadding {
133             get {
134                 string s = Attributes["cellpadding"];
135                 return((s != null) ? Int32.Parse(s, CultureInfo.InvariantCulture) : -1);
136             }
137             set {
138                 Attributes["cellpadding"] = MapIntegerAttributeToString(value);
139             }
140         }
141 
142 
143         /// <devdoc>
144         ///    <para>
145         ///       Gets or sets the cell spacing, in pixels, for an <see langword='HtmlTable'/> control.
146         ///    </para>
147         /// </devdoc>
148         [
149         WebCategory("Appearance"),
150         DefaultValue(""),
151         DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
152         ]
153         public int CellSpacing {
154             get {
155                 string s = Attributes["cellspacing"];
156                 return((s != null) ? Int32.Parse(s, CultureInfo.InvariantCulture) : -1);
157             }
158             set {
159                 Attributes["cellspacing"] = MapIntegerAttributeToString(value);
160             }
161         }
162 
163 
164         /// <devdoc>
165         ///    <para>[To be supplied.]</para>
166         /// </devdoc>
167         public override string InnerHtml {
168             get {
169                 throw new NotSupportedException(SR.GetString(SR.InnerHtml_not_supported, this.GetType().Name));
170             }
171             set {
172                 throw new NotSupportedException(SR.GetString(SR.InnerHtml_not_supported, this.GetType().Name));
173             }
174         }
175 
176 
177         /// <devdoc>
178         ///    <para>[To be supplied.]</para>
179         /// </devdoc>
180         public override string InnerText {
181             get {
182                 throw new NotSupportedException(SR.GetString(SR.InnerText_not_supported, this.GetType().Name));
183             }
184             set {
185                 throw new NotSupportedException(SR.GetString(SR.InnerText_not_supported, this.GetType().Name));
186             }
187         }
188 
189 
190         /// <devdoc>
191         ///    <para>
192         ///       Gets or sets the height of an <see langword='HtmlTable'/>
193         ///       control.
194         ///    </para>
195         /// </devdoc>
196         [
197         WebCategory("Layout"),
198         DefaultValue(""),
199         DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
200         ]
201         public string Height {
202             get {
203                 string s = Attributes["height"];
204                 return((s != null) ? s : String.Empty);
205             }
206 
207             set {
208                 Attributes["height"] = MapStringAttributeToString(value);
209             }
210         }
211 
212 
213         /// <devdoc>
214         ///    <para>
215         ///       Gets or sets the width of an <see langword='HtmlTable'/> control.
216         ///    </para>
217         /// </devdoc>
218         [
219         WebCategory("Layout"),
220         DefaultValue(""),
221         DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
222         ]
223         public string Width {
224             get {
225                 string s = Attributes["width"];
226                 return((s != null) ? s : String.Empty);
227             }
228 
229             set {
230                 Attributes["width"] = MapStringAttributeToString(value);
231             }
232         }
233 
234 
235         /// <devdoc>
236         ///    <para>
237         ///       Gets a collection that contains all of the rows in an
238         ///    <see langword='HtmlTable'/> control. An empty collection is returned if no
239         ///       &lt;tr&gt; elements are contained within the control.
240         ///    </para>
241         /// </devdoc>
242         [
243         Browsable(false),
244         DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
245         IgnoreUnknownContent()
246         ]
247         public virtual HtmlTableRowCollection Rows {
248             get {
249                 if (rows == null)
250                     rows = new HtmlTableRowCollection(this);
251 
252                 return rows;
253             }
254         }
255 
256 
257         /// <internalonly/>
258         /// <devdoc>
259         /// </devdoc>
RenderChildren(HtmlTextWriter writer)260         protected internal override void RenderChildren(HtmlTextWriter writer) {
261             writer.WriteLine();
262             writer.Indent++;
263             base.RenderChildren(writer);
264 
265             writer.Indent--;
266         }
267 
268 
269         /// <internalonly/>
270         /// <devdoc>
271         /// </devdoc>
RenderEndTag(HtmlTextWriter writer)272         protected override void RenderEndTag(HtmlTextWriter writer) {
273             base.RenderEndTag(writer);
274             writer.WriteLine();
275         }
276 
277 
278         /// <devdoc>
279         ///    <para>[To be supplied.]</para>
280         /// </devdoc>
CreateControlCollection()281         protected override ControlCollection CreateControlCollection() {
282             return new HtmlTableRowControlCollection(this);
283         }
284 
285 
286         /// <devdoc>
287         ///    <para>[To be supplied.]</para>
288         /// </devdoc>
289         protected class HtmlTableRowControlCollection : ControlCollection {
290 
HtmlTableRowControlCollection(Control owner)291             internal HtmlTableRowControlCollection (Control owner) : base(owner) {
292             }
293 
294 
295             /// <devdoc>
296             /// <para>Adds the specified <see cref='System.Web.UI.Control'/> object to the collection. The new control is added
297             ///    to the end of the array.</para>
298             /// </devdoc>
Add(Control child)299             public override void Add(Control child) {
300                 if (child is HtmlTableRow)
301                     base.Add(child);
302                 else
303                     throw new ArgumentException(SR.GetString(SR.Cannot_Have_Children_Of_Type, "HtmlTable", child.GetType().Name.ToString(CultureInfo.InvariantCulture))); // throw an exception here
304             }
305 
306 
307             /// <devdoc>
308             /// <para>Adds the specified <see cref='System.Web.UI.Control'/> object to the collection. The new control is added
309             ///    to the array at the specified index location.</para>
310             /// </devdoc>
AddAt(int index, Control child)311             public override void AddAt(int index, Control child) {
312                 if (child is HtmlTableRow)
313                     base.AddAt(index, child);
314                 else
315                     throw new ArgumentException(SR.GetString(SR.Cannot_Have_Children_Of_Type, "HtmlTable", child.GetType().Name.ToString(CultureInfo.InvariantCulture))); // throw an exception here
316             }
317         } // class HtmlTableRowControlCollection
318 
319     }
320 }
321