2 // System.Web.UI.WebControls.Table.cs
5 // Gaurav Vaish (gvaish@iitk.ac.in)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 // (C) Gaurav Vaish (2002)
9 // (C) 2003 Andreas Nahr
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Drawing;
\r
35 using System.Globalization;
\r
37 using System.Web.UI;
\r
38 using System.ComponentModel;
39 using System.ComponentModel.Design;
\r
41 namespace System.Web.UI.WebControls
\r
43 [DefaultProperty("Rows")]
\r
44 [Designer ("System.Web.UI.Design.WebControls.TableDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
\r
45 [ParseChildren(true, "Rows")]
\r
46 public class Table: WebControl
\r
48 private TableRowCollection rows;
\r
50 private class TableRowControlCollection : ControlCollection
\r
52 public TableRowControlCollection (Control owner) : base (owner)
\r
56 public override void Add (Control child)
\r
58 if (!(child is TableRow))
\r
59 throw new ArgumentException (HttpRuntime.FormatResourceString (
\r
60 "Cannot_Have_Children_Of_Type",
\r
62 child.GetType ().Name.ToString ()));
\r
66 public override void AddAt(int index, Control child)
\r
68 if (!(child is TableRow))
\r
69 throw new ArgumentException (HttpRuntime.FormatResourceString (
\r
70 "Cannot_Have_Children_Of_Type",
\r
72 child.GetType ().Name.ToString ()));
\r
73 base.AddAt (index, child);
\r
77 public Table () : base (HtmlTextWriterTag.Table)
\r
86 [DefaultValue (""), WebCategory ("Appearance")]
87 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
88 [WebSysDescription ("An Url specifying the background image for the table.")]
\r
89 public virtual string BackImageUrl
\r
92 if (ControlStyleCreated)
\r
93 return ((TableStyle) ControlStyle).BackImageUrl;
\r
94 return String.Empty;
\r
97 set { ((TableStyle) ControlStyle).BackImageUrl = value; }
\r
101 [DefaultValue (""), WebCategory ("Accessibility")]
\r
102 public virtual string Caption
\r
105 object o = ViewState ["Caption"];
\r
106 if(o != null) return (string)o;
\r
110 ViewState ["Caption"] = value;
\r
114 [DefaultValue (""), WebCategory ("Accessibility")]
\r
115 public virtual TableCaptionAlign CaptionAlign
\r
118 object o = ViewState ["CaptionAlign"];
\r
119 if(o != null) return (TableCaptionAlign) o;
\r
120 return TableCaptionAlign.NotSet;
\r
123 ViewState ["CaptionAlign"] = value;
\r
131 [DefaultValue (-1), WebCategory ("Appearance")]
132 [WebSysDescription ("The space left around the borders within a cell.")]
\r
133 public virtual int CellPadding
\r
136 if (ControlStyleCreated)
\r
137 return ((TableStyle) ControlStyle).CellPadding;
\r
141 set { ((TableStyle) ControlStyle).CellPadding = value; }
\r
147 [DefaultValue (-1), WebCategory ("Appearance")]
148 [WebSysDescription ("The space left between cells.")]
\r
149 public virtual int CellSpacing
\r
152 if (ControlStyleCreated)
\r
153 return ((TableStyle) ControlStyle).CellSpacing;
\r
157 set { ((TableStyle) ControlStyle).CellSpacing = value; }
\r
163 [DefaultValue (typeof (GridLines), "None"), WebCategory ("Appearance")]
164 [WebSysDescription ("The type of grid that a table uses.")]
\r
165 public virtual GridLines GridLines
\r
168 if (ControlStyleCreated)
\r
169 return ((TableStyle) ControlStyle).GridLines;
\r
170 return GridLines.None;
\r
173 set { ((TableStyle) ControlStyle).GridLines = value; }
\r
179 [DefaultValue (typeof (HorizontalAlign), "NotSet"), WebCategory ("Layout")]
180 [WebSysDescription ("The horizonal alignment of the table.")]
\r
181 public virtual HorizontalAlign HorizontalAlign
\r
184 if (ControlStyleCreated)
\r
185 return ((TableStyle) ControlStyle).HorizontalAlign;
\r
186 return HorizontalAlign.NotSet;
\r
189 set { ((TableStyle) ControlStyle).HorizontalAlign = value; }
\r
192 [MergableProperty (false), PersistenceMode (PersistenceMode.InnerDefaultProperty)]
193 [WebSysDescription ("The rows of this table.")]
\r
194 public virtual TableRowCollection Rows
\r
198 rows = new TableRowCollection (this);
\r
203 protected override void AddAttributesToRender (HtmlTextWriter writer)
\r
205 base.AddAttributesToRender (writer);
\r
206 if(!BorderColor.IsEmpty)
\r
207 writer.AddAttribute (HtmlTextWriterAttribute.Bordercolor,
\r
208 ColorTranslator.ToHtml (BorderColor));
\r
210 Unit bw = BorderWidth;
\r
211 if (GridLines == GridLines.None)
\r
212 bw = Unit.Pixel (0);
\r
213 else if (bw.IsEmpty || bw.Type != UnitType.Pixel)
\r
214 bw = Unit.Pixel(1);
\r
216 writer.AddAttribute (HtmlTextWriterAttribute.Border,
\r
217 ((int) bw.Value).ToString (NumberFormatInfo.InvariantInfo));
\r
220 protected override ControlCollection CreateControlCollection ()
\r
222 return new TableRowControlCollection (this);
\r
225 protected override Style CreateControlStyle ()
\r
227 return new TableStyle (ViewState);
\r
230 protected override void RenderContents (HtmlTextWriter writer)
\r
232 foreach (TableRow current in Rows)
\r
233 current.RenderControl (writer);
\r