2 // System.Web.UI.WebControls.Table.cs
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.ComponentModel;
30 using System.Security.Permissions;
32 namespace System.Web.UI.WebControls {
35 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
36 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
38 [DefaultProperty ("Rows")]
39 [Designer ("System.Web.UI.Design.WebControls.TableDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
40 [ParseChildren (true, "Rows")]
42 [SupportsEventValidation]
43 public class Table : WebControl, IPostBackEventHandler {
45 public class Table : WebControl {
47 private TableRowCollection rows;
51 : base (HtmlTextWriterTag.Table)
57 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
61 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
64 [WebSysDescription ("")]
65 [WebCategory ("Appearance")]
66 public virtual string BackImageUrl {
68 if (!ControlStyleCreated)
69 return String.Empty; // default value
70 return TableStyle.BackImageUrl;
72 set { TableStyle.BackImageUrl = value; }
75 // note: it seems that Caption and CaptionAlign appeared in 1.1 SP1
81 [WebSysDescription ("")]
82 [WebCategory ("Accessibility")]
83 public virtual string Caption {
85 object o = ViewState ["Caption"];
86 return (o == null) ? String.Empty : (string) o;
90 ViewState.Remove ("Caption");
92 ViewState ["Caption"] = value;
96 [DefaultValue (TableCaptionAlign.NotSet)]
97 [WebCategory ("Accessibility")]
98 public virtual TableCaptionAlign CaptionAlign {
100 object o = ViewState ["CaptionAlign"];
101 return (o == null) ? TableCaptionAlign.NotSet : (TableCaptionAlign) o;
104 if ((value < TableCaptionAlign.NotSet) || (value > TableCaptionAlign.Right)) {
105 throw new ArgumentOutOfRangeException (Locale.GetText ("Invalid TableCaptionAlign value."));
107 ViewState ["CaptionAlign"] = value;
115 [WebSysDescription ("")]
116 [WebCategory ("Appearance")]
117 public virtual int CellPadding {
119 if (!ControlStyleCreated)
120 return -1; // default value
121 return TableStyle.CellPadding;
123 set { TableStyle.CellPadding = value; }
130 [WebSysDescription ("")]
131 [WebCategory ("Appearance")]
132 public virtual int CellSpacing {
134 if (!ControlStyleCreated)
135 return -1; // default value
136 return TableStyle.CellSpacing;
138 set { TableStyle.CellSpacing = value; }
144 [DefaultValue (GridLines.None)]
145 [WebSysDescription ("")]
146 [WebCategory ("Appearance")]
147 public virtual GridLines GridLines {
149 if (!ControlStyleCreated)
150 return GridLines.None; // default value
151 return TableStyle.GridLines;
153 set { TableStyle.GridLines = value; }
159 [DefaultValue (HorizontalAlign.NotSet)]
160 [WebSysDescription ("")]
161 [WebCategory ("Layout")]
162 public virtual HorizontalAlign HorizontalAlign {
164 if (!ControlStyleCreated)
165 return HorizontalAlign.NotSet; // default value
166 return TableStyle.HorizontalAlign;
168 set { TableStyle.HorizontalAlign = value; }
171 [MergableProperty (false)]
172 [PersistenceMode (PersistenceMode.InnerDefaultProperty)]
173 [WebSysDescription ("")]
174 public virtual TableRowCollection Rows {
177 rows = new TableRowCollection (this);
182 private TableStyle TableStyle {
183 get { return (ControlStyle as TableStyle); }
187 protected override void AddAttributesToRender (HtmlTextWriter writer)
189 base.AddAttributesToRender (writer);
190 if (!ControlStyleCreated || TableStyle.IsEmpty) {
191 // for some reason border=X seems to be always present
192 // and isn't rendered as a style attribute
193 writer.AddAttribute (HtmlTextWriterAttribute.Border, "0");
197 protected override ControlCollection CreateControlCollection ()
199 return new RowControlCollection (this);
202 protected override Style CreateControlStyle ()
204 return new TableStyle (ViewState);
212 override void RenderContents (HtmlTextWriter writer)
214 if (Rows.Count > 0) {
216 foreach (TableRow row in Rows)
218 row.RenderControl (writer);
224 // new in Fx 1.1 SP1 (to support Caption and CaptionAlign)
226 public override void RenderBeginTag (HtmlTextWriter writer)
228 base.RenderBeginTag (writer);
232 writer.WriteBeginTag ("caption");
234 TableCaptionAlign tca = CaptionAlign;
235 if (tca != TableCaptionAlign.NotSet) {
236 writer.WriteAttribute ("align", tca.ToString ());
239 writer.Write (HtmlTextWriter.TagRightChar);
245 writer.WriteEndTag ("caption");
246 } else if (HasControls ()) {
252 void IPostBackEventHandler.RaisePostBackEvent (string argument)
254 RaisePostBackEvent (argument);
257 protected virtual void RaisePostBackEvent (string argument)
263 protected class RowControlCollection : ControlCollection {
265 internal RowControlCollection (Table owner)
271 public override void Add (Control child)
274 throw new NullReferenceException ("null");
275 if (!(child is TableRow))
276 throw new ArgumentException ("child", Locale.GetText ("Must be an TableRow instance."));
281 public override void AddAt (int index, Control child)
284 throw new NullReferenceException ("null");
285 if (!(child is TableRow))
286 throw new ArgumentException ("child", Locale.GetText ("Must be an TableRow instance."));
288 base.AddAt (index, child);