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")]
41 [SupportsEventValidation
]
42 public class Table
: WebControl
, IPostBackEventHandler
44 TableRowCollection rows
;
45 bool generateTableSections
;
48 : base (HtmlTextWriterTag
.Table
)
52 internal bool GenerateTableSections
{
53 get { return generateTableSections; }
54 set { generateTableSections = value; }
57 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts
.AssemblySystem_Design
, "System.Drawing.Design.UITypeEditor, " + Consts
.AssemblySystem_Drawing
)]
60 [WebSysDescription ("")]
61 [WebCategory ("Appearance")]
62 public virtual string BackImageUrl
{
64 if (!ControlStyleCreated
)
65 return String
.Empty
; // default value
66 return TableStyle
.BackImageUrl
;
68 set { TableStyle.BackImageUrl = value; }
71 // note: it seems that Caption and CaptionAlign appeared in 1.1 SP1
75 [WebSysDescription ("")]
76 [WebCategory ("Accessibility")]
77 public virtual string Caption
{
79 object o
= ViewState
["Caption"];
80 return (o
== null) ? String
.Empty
: (string) o
;
84 ViewState
.Remove ("Caption");
86 ViewState
["Caption"] = value;
90 [DefaultValue (TableCaptionAlign
.NotSet
)]
91 [WebCategory ("Accessibility")]
92 public virtual TableCaptionAlign CaptionAlign
{
94 object o
= ViewState
["CaptionAlign"];
95 return (o
== null) ? TableCaptionAlign
.NotSet
: (TableCaptionAlign
) o
;
98 if ((value < TableCaptionAlign
.NotSet
) || (value > TableCaptionAlign
.Right
)) {
99 throw new ArgumentOutOfRangeException (Locale
.GetText ("Invalid TableCaptionAlign value."));
101 ViewState
["CaptionAlign"] = value;
106 [WebSysDescription ("")]
107 [WebCategory ("Appearance")]
108 public virtual int CellPadding
{
110 if (!ControlStyleCreated
)
111 return -1; // default value
112 return TableStyle
.CellPadding
;
114 set { TableStyle.CellPadding = value; }
118 [WebSysDescription ("")]
119 [WebCategory ("Appearance")]
120 public virtual int CellSpacing
{
122 if (!ControlStyleCreated
)
123 return -1; // default value
124 return TableStyle
.CellSpacing
;
126 set { TableStyle.CellSpacing = value; }
129 [DefaultValue (GridLines
.None
)]
130 [WebSysDescription ("")]
131 [WebCategory ("Appearance")]
132 public virtual GridLines GridLines
{
134 if (!ControlStyleCreated
)
135 return GridLines
.None
; // default value
136 return TableStyle
.GridLines
;
138 set { TableStyle.GridLines = value; }
141 [DefaultValue (HorizontalAlign
.NotSet
)]
142 [WebSysDescription ("")]
143 [WebCategory ("Layout")]
144 public virtual HorizontalAlign HorizontalAlign
{
146 if (!ControlStyleCreated
)
147 return HorizontalAlign
.NotSet
; // default value
148 return TableStyle
.HorizontalAlign
;
150 set { TableStyle.HorizontalAlign = value; }
153 [MergableProperty (false)]
154 [PersistenceMode (PersistenceMode
.InnerDefaultProperty
)]
155 [WebSysDescription ("")]
156 public virtual TableRowCollection Rows
{
159 rows
= new TableRowCollection (this);
164 private TableStyle TableStyle
{
165 get { return (ControlStyle as TableStyle); }
167 public override bool SupportsDisabledAttribute
{
168 get { return RenderingCompatibilityLessThan40; }
170 protected override void AddAttributesToRender (HtmlTextWriter writer
)
172 base.AddAttributesToRender (writer
);
175 protected override ControlCollection
CreateControlCollection ()
177 return new RowControlCollection (this);
180 protected override Style
CreateControlStyle ()
182 return new TableStyle (ViewState
);
186 override void RenderContents (HtmlTextWriter writer
)
188 TableRowSection currentTableSection
= TableRowSection
.TableHeader
;
189 TableRowSection rowSection
;
190 bool sectionStarted
= false;
192 if (Rows
.Count
> 0) {
193 foreach (TableRow row
in Rows
) {
194 if (generateTableSections
) {
195 rowSection
= row
.TableSection
;
196 if (rowSection
< currentTableSection
)
197 throw new HttpException ("The table " + ID
+ " must contain row sections in order of header, body, then footer.");
199 if (currentTableSection
!= rowSection
) {
200 if (sectionStarted
) {
201 writer
.RenderEndTag ();
202 sectionStarted
= false;
205 currentTableSection
= rowSection
;
208 if (!sectionStarted
) {
209 switch (rowSection
) {
210 case TableRowSection
.TableHeader
:
211 writer
.RenderBeginTag (HtmlTextWriterTag
.Thead
);
214 case TableRowSection
.TableBody
:
215 writer
.RenderBeginTag (HtmlTextWriterTag
.Tbody
);
218 case TableRowSection
.TableFooter
:
219 writer
.RenderBeginTag (HtmlTextWriterTag
.Tfoot
);
222 sectionStarted
= true;
226 row
.RenderControl (writer
);
230 writer
.RenderEndTag ();
235 // new in Fx 1.1 SP1 (to support Caption and CaptionAlign)
237 public override void RenderBeginTag (HtmlTextWriter writer
)
239 base.RenderBeginTag (writer
);
243 TableCaptionAlign tca
= CaptionAlign
;
244 if (tca
!= TableCaptionAlign
.NotSet
)
245 writer
.AddAttribute (HtmlTextWriterAttribute
.Align
, tca
.ToString ());
247 writer
.RenderBeginTag (HtmlTextWriterTag
.Caption
);
249 writer
.RenderEndTag ();
252 // else if (HasControls ()) {
258 void IPostBackEventHandler
.RaisePostBackEvent (string argument
)
260 RaisePostBackEvent (argument
);
263 protected virtual void RaisePostBackEvent (string argument
)
265 ValidateEvent (UniqueID
, argument
);
269 protected class RowControlCollection
: ControlCollection
{
271 internal RowControlCollection (Table owner
)
277 public override void Add (Control child
)
280 throw new NullReferenceException ("null");
281 if (!(child
is TableRow
))
282 throw new ArgumentException ("child", Locale
.GetText ("Must be an TableRow instance."));
287 public override void AddAt (int index
, Control child
)
290 throw new NullReferenceException ("null");
291 if (!(child
is TableRow
))
292 throw new ArgumentException ("child", Locale
.GetText ("Must be an TableRow instance."));
294 base.AddAt (index
, child
);