2 // System.Web.UI.WebControls.DataControlField.cs
5 // Sanjay Gupta (gsanjay@novell.com)
6 // Lluis Sanchez Gual (lluis@novell.com)
8 // (C) 2004 Novell, Inc. (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Collections;
34 using System.Collections.Specialized;
36 using System.ComponentModel;
37 using System.Security.Permissions;
39 namespace System.Web.UI.WebControls {
41 [DefaultPropertyAttribute ("HeaderText")]
42 [TypeConverterAttribute (typeof(ExpandableObjectConverter))]
43 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
44 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
45 public abstract class DataControlField : IStateManager, IDataSourceViewSchemaAccessor
47 bool tracking = false;
51 TableItemStyle footerStyle;
52 TableItemStyle headerStyle;
53 TableItemStyle itemStyle;
56 protected DataControlField()
58 viewState = new StateBag ();
61 internal void SetDirty ()
63 viewState.SetDirty ();
66 protected StateBag ViewState {
67 get { return viewState; }
70 public virtual void ExtractValuesFromCell (IOrderedDictionary dictionary,
71 DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly)
75 public virtual bool Initialize (bool sortingEnabled, Control control)
77 this.sortingEnabled = sortingEnabled;
78 this.control = control;
82 public virtual void InitializeCell (DataControlFieldCell cell,
83 DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
85 if (cellType == DataControlCellType.Header && ShowHeader)
87 if (HeaderText.Length > 0 || HeaderImageUrl.Length > 0) {
88 if (sortingEnabled && SortExpression.Length > 0)
89 cell.Controls.Add (new DataControlButton (control, HeaderText, HeaderImageUrl, "Sort", SortExpression, true));
91 cell.Controls.Add (new DataControlButton (control, HeaderText, HeaderImageUrl, string.Empty, string.Empty, true));
94 else if (cellType == DataControlCellType.Footer) {
95 cell.Text = FooterText;
99 protected virtual void OnFieldChanged ()
101 if (FieldChanged != null)
102 FieldChanged (this, EventArgs.Empty);
105 protected virtual void LoadViewState (object savedState)
107 if (savedState == null)
110 object [] states = (object []) savedState;
111 viewState.LoadViewState (states[0]);
113 if (states[1] != null)
114 ((IStateManager)controlStyle).LoadViewState (states[1]);
115 if (states[2] != null)
116 ((IStateManager)footerStyle).LoadViewState (states[2]);
117 if (states[3] != null)
118 ((IStateManager)headerStyle).LoadViewState (states[3]);
119 if (states[4] != null)
120 ((IStateManager)itemStyle).LoadViewState (states[4]);
123 protected virtual object SaveViewState()
125 object[] state = new object [5];
126 state [0] = viewState.SaveViewState ();
127 if (controlStyle != null)
128 state [1] = ((IStateManager) controlStyle).SaveViewState ();
129 if (footerStyle != null)
130 state [2] = ((IStateManager) footerStyle).SaveViewState ();
131 if (headerStyle != null)
132 state [3] = ((IStateManager) headerStyle).SaveViewState ();
133 if (itemStyle != null)
134 state [4] = ((IStateManager) itemStyle).SaveViewState ();
136 if (state [0] == null && state [1] == null && state [2] == null &&
137 state [3] == null && state [4] == null)
143 protected virtual void TrackViewState()
145 if (controlStyle != null) ((IStateManager) controlStyle).TrackViewState ();
146 if (footerStyle != null) ((IStateManager) footerStyle).TrackViewState ();
147 if (headerStyle != null) ((IStateManager) headerStyle).TrackViewState ();
148 if (itemStyle != null) ((IStateManager) itemStyle).TrackViewState ();
149 viewState.TrackViewState ();
153 public virtual void ValidateSupportsCallback ()
155 throw new NotSupportedException ("Callback not supported");
158 void IStateManager.LoadViewState(object savedState)
160 LoadViewState(savedState);
163 object IStateManager.SaveViewState()
165 return SaveViewState();
168 void IStateManager.TrackViewState()
173 internal Exception GetNotSupportedPropException (string propName)
175 return new System.NotSupportedException ("The property '" + propName + "' is not supported in " + GetType().Name);
178 [MonoTODO ("Render this")]
179 [DefaultValueAttribute ("")]
180 [LocalizableAttribute (true)]
181 [WebCategoryAttribute ("Accessibility")]
182 public virtual string AccessibleHeaderText {
184 object val = viewState ["accessibleHeaderText"];
185 return val != null ? (string) val : "";
188 viewState ["accessibleHeaderText"] = value;
193 protected Control Control {
194 get { return control; }
197 [WebCategoryAttribute ("Styles")]
198 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
199 [DefaultValueAttribute (null)]
200 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
201 public virtual Style ControlStyle {
203 if (controlStyle == null) {
204 controlStyle = new Style ();
205 if (IsTrackingViewState)
206 controlStyle.TrackViewState();
212 protected bool DesignMode {
213 get { return control != null && control.Site != null ? control.Site.DesignMode : false; }
216 [DefaultValueAttribute (null)]
217 [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
218 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
219 [WebCategoryAttribute ("Styles")]
220 public virtual TableItemStyle FooterStyle {
222 if (footerStyle == null) {
223 footerStyle = new TableItemStyle ();
224 if (IsTrackingViewState)
225 footerStyle.TrackViewState();
231 [LocalizableAttribute (true)]
232 [WebCategoryAttribute ("Appearance")]
234 public virtual string FooterText {
236 object val = viewState ["footerText"];
237 return val != null ? (string) val : "";
240 viewState ["footerText"] = value;
245 [UrlPropertyAttribute]
246 [DefaultValueAttribute ("")]
247 [EditorAttribute ("System.Web.UI.Design.UrlEditor, System.Design, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
248 [WebCategoryAttribute ("Appearance")]
249 public virtual string HeaderImageUrl {
251 object val = viewState ["headerImageUrl"];
252 return val != null ? (string) val : "";
255 viewState ["headerImageUrl"] = value;
260 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
261 [WebCategoryAttribute ("Styles")]
262 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
263 [DefaultValueAttribute (null)]
264 public virtual TableItemStyle HeaderStyle {
266 if (headerStyle == null) {
267 headerStyle = new TableItemStyle ();
268 if (IsTrackingViewState)
269 headerStyle.TrackViewState();
275 [DefaultValueAttribute ("")]
276 [LocalizableAttribute (true)]
277 [WebCategoryAttribute ("Appearance")]
278 public virtual string HeaderText {
280 object val = viewState ["headerText"];
281 return val != null ? (string) val : "";
284 viewState ["headerText"] = value;
289 [WebCategoryAttribute ("Behavior")]
290 [DefaultValueAttribute (true)]
291 public virtual bool InsertVisible {
293 object val = viewState ["InsertVisible"];
294 return val != null ? (bool) val : true;
297 viewState ["InsertVisible"] = value;
302 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
303 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
304 [WebCategoryAttribute ("Styles")]
305 [DefaultValueAttribute (null)]
306 public virtual TableItemStyle ItemStyle {
308 if (itemStyle == null) {
309 itemStyle = new TableItemStyle ();
310 if (IsTrackingViewState)
311 itemStyle.TrackViewState();
317 [WebCategoryAttribute ("Behavior")]
318 [DefaultValueAttribute (true)]
319 public virtual bool ShowHeader {
321 object val = viewState ["showHeader"];
322 return val != null ? (bool) val : true;
325 viewState ["showHeader"] = value;
330 [DefaultValueAttribute ("")]
331 // [TypeConverterAttribute ("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
332 [WebCategoryAttribute ("Behavior")]
333 public virtual string SortExpression {
335 object val = viewState ["sortExpression"];
336 return val != null ? (string) val : "";
339 viewState ["sortExpression"] = value;
344 [WebCategoryAttribute ("Behavior")]
345 [DefaultValueAttribute (true)]
346 public bool Visible {
348 object val = viewState ["visible"];
349 return val != null ? (bool) val : true;
352 viewState ["visible"] = value;
357 protected bool IsTrackingViewState
359 get { return tracking; }
362 bool IStateManager.IsTrackingViewState
364 get { return IsTrackingViewState; }
367 object IDataSourceViewSchemaAccessor.DataSourceViewSchema {
368 get { return viewState ["dataSourceViewSchema"]; }
370 viewState ["dataSourceViewSchema"] = value;
374 internal event EventHandler FieldChanged;