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
81 [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
82 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
83 [WebSysDescription ("An Url specifying the background image for the table.")]
\r
84 public virtual string BackImageUrl
\r
87 if (ControlStyleCreated)
\r
88 return ((TableStyle) ControlStyle).BackImageUrl;
\r
89 return String.Empty;
\r
92 set { ((TableStyle) ControlStyle).BackImageUrl = value; }
\r
95 [DefaultValue (-1), Bindable (true), WebCategory ("Appearance")]
96 [WebSysDescription ("The space left around the borders within a cell.")]
\r
97 public virtual int CellPadding
\r
100 if (ControlStyleCreated)
\r
101 return ((TableStyle) ControlStyle).CellPadding;
\r
105 set { ((TableStyle) ControlStyle).CellPadding = value; }
\r
108 [DefaultValue (-1), Bindable (true), WebCategory ("Appearance")]
109 [WebSysDescription ("The space left between cells.")]
\r
110 public virtual int CellSpacing
\r
113 if (ControlStyleCreated)
\r
114 return ((TableStyle) ControlStyle).CellSpacing;
\r
118 set { ((TableStyle) ControlStyle).CellSpacing = value; }
\r
121 [DefaultValue (typeof (GridLines), "None"), Bindable (true), WebCategory ("Appearance")]
122 [WebSysDescription ("The type of grid that a table uses.")]
\r
123 public virtual GridLines GridLines
\r
126 if (ControlStyleCreated)
\r
127 return ((TableStyle) ControlStyle).GridLines;
\r
128 return GridLines.None;
\r
131 set { ((TableStyle) ControlStyle).GridLines = value; }
\r
134 [DefaultValue (typeof (HorizontalAlign), "NotSet"), Bindable (true), WebCategory ("Layout")]
135 [WebSysDescription ("The horizonal alignment of the table.")]
\r
136 public virtual HorizontalAlign HorizontalAlign
\r
139 if (ControlStyleCreated)
\r
140 return ((TableStyle) ControlStyle).HorizontalAlign;
\r
141 return HorizontalAlign.NotSet;
\r
144 set { ((TableStyle) ControlStyle).HorizontalAlign = value; }
\r
147 [MergableProperty (false), PersistenceMode (PersistenceMode.InnerDefaultProperty)]
148 [WebSysDescription ("The rows of this table.")]
\r
149 public virtual TableRowCollection Rows
\r
153 rows = new TableRowCollection (this);
\r
158 protected override void AddAttributesToRender (HtmlTextWriter writer)
\r
160 base.AddAttributesToRender (writer);
\r
161 if(!BorderColor.IsEmpty)
\r
162 writer.AddAttribute (HtmlTextWriterAttribute.Bordercolor,
\r
163 ColorTranslator.ToHtml (BorderColor));
\r
165 Unit bw = BorderWidth;
\r
166 if (GridLines == GridLines.None)
\r
167 bw = Unit.Pixel (0);
\r
168 else if (bw.IsEmpty || bw.Type != UnitType.Pixel)
\r
169 bw = Unit.Pixel(1);
\r
171 writer.AddAttribute (HtmlTextWriterAttribute.Border,
\r
172 ((int) bw.Value).ToString (NumberFormatInfo.InvariantInfo));
\r
175 protected override ControlCollection CreateControlCollection ()
\r
177 return new TableRowControlCollection (this);
\r
180 protected override Style CreateControlStyle ()
\r
182 return new TableStyle (ViewState);
\r
185 protected override void RenderContents (HtmlTextWriter writer)
\r
187 foreach (TableRow current in Rows)
\r
188 current.RenderControl (writer);
\r