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 using System.Drawing;
\r
14 using System.Globalization;
\r
16 using System.Web.UI;
\r
17 using System.ComponentModel;
18 using System.ComponentModel.Design;
\r
20 namespace System.Web.UI.WebControls
\r
22 [DefaultProperty("Rows")]
\r
23 [Designer ("System.Web.UI.Design.WebControls.TableDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
\r
24 [ParseChildren(true, "Rows")]
\r
25 public class Table: WebControl
\r
27 private TableRowCollection rows;
\r
29 private class TableRowControlCollection : ControlCollection
\r
31 public TableRowControlCollection (Control owner) : base (owner)
\r
35 public override void Add (Control child)
\r
37 if (!(child is TableRow))
\r
38 throw new ArgumentException (HttpRuntime.FormatResourceString (
\r
39 "Cannot_Have_Children_Of_Type",
\r
41 child.GetType ().Name.ToString ()));
\r
45 public override void AddAt(int index, Control child)
\r
47 if (!(child is TableRow))
\r
48 throw new ArgumentException (HttpRuntime.FormatResourceString (
\r
49 "Cannot_Have_Children_Of_Type",
\r
51 child.GetType ().Name.ToString ()));
\r
52 base.AddAt (index, child);
\r
56 public Table () : base (HtmlTextWriterTag.Table)
\r
60 [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
61 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
62 [WebSysDescription ("An Url specifying the background image for the table.")]
\r
63 public virtual string BackImageUrl
\r
66 if (ControlStyleCreated)
\r
67 return ((TableStyle) ControlStyle).BackImageUrl;
\r
68 return String.Empty;
\r
71 set { ((TableStyle) ControlStyle).BackImageUrl = value; }
\r
74 [DefaultValue (-1), Bindable (true), WebCategory ("Appearance")]
75 [WebSysDescription ("The space left around the borders within a cell.")]
\r
76 public virtual int CellPadding
\r
79 if (ControlStyleCreated)
\r
80 return ((TableStyle) ControlStyle).CellPadding;
\r
84 set { ((TableStyle) ControlStyle).CellPadding = value; }
\r
87 [DefaultValue (-1), Bindable (true), WebCategory ("Appearance")]
88 [WebSysDescription ("The space left between cells.")]
\r
89 public virtual int CellSpacing
\r
92 if (ControlStyleCreated)
\r
93 return ((TableStyle) ControlStyle).CellSpacing;
\r
97 set { ((TableStyle) ControlStyle).CellSpacing = value; }
\r
100 [DefaultValue (typeof (GridLines), "None"), Bindable (true), WebCategory ("Appearance")]
101 [WebSysDescription ("The type of grid that a table uses.")]
\r
102 public virtual GridLines GridLines
\r
105 if (ControlStyleCreated)
\r
106 return ((TableStyle) ControlStyle).GridLines;
\r
107 return GridLines.None;
\r
110 set { ((TableStyle) ControlStyle).GridLines = value; }
\r
113 [DefaultValue (typeof (HorizontalAlign), "NotSet"), Bindable (true), WebCategory ("Layout")]
114 [WebSysDescription ("The horizonal alignment of the table.")]
\r
115 public virtual HorizontalAlign HorizontalAlign
\r
118 if (ControlStyleCreated)
\r
119 return ((TableStyle) ControlStyle).HorizontalAlign;
\r
120 return HorizontalAlign.NotSet;
\r
123 set { ((TableStyle) ControlStyle).HorizontalAlign = value; }
\r
126 [MergableProperty (false), PersistenceMode (PersistenceMode.InnerDefaultProperty)]
127 [WebSysDescription ("The rows of this table.")]
\r
128 public virtual TableRowCollection Rows
\r
132 rows = new TableRowCollection (this);
\r
137 protected override void AddAttributesToRender (HtmlTextWriter writer)
\r
139 base.AddAttributesToRender (writer);
\r
140 if(!BorderColor.IsEmpty)
\r
141 writer.AddAttribute (HtmlTextWriterAttribute.Bordercolor,
\r
142 ColorTranslator.ToHtml (BorderColor));
\r
144 Unit bw = BorderWidth;
\r
145 if (GridLines == GridLines.None)
\r
146 bw = Unit.Pixel (0);
\r
147 else if (bw.IsEmpty || bw.Type != UnitType.Pixel)
\r
148 bw = Unit.Pixel(1);
\r
150 writer.AddAttribute (HtmlTextWriterAttribute.Border,
\r
151 ((int) bw.Value).ToString (NumberFormatInfo.InvariantInfo));
\r
154 protected override ControlCollection CreateControlCollection ()
\r
156 return new TableRowControlCollection (this);
\r
159 protected override Style CreateControlStyle ()
\r
161 return new TableStyle (ViewState);
\r
164 protected override void RenderContents (HtmlTextWriter writer)
\r
166 foreach (TableRow current in Rows)
\r
167 current.RenderControl (writer);
\r