2 // System.Web.UI.WebControls.HierarchicalDataBoundControl.cs
5 // Lluis Sanchez Gual (lluis@novell.com)
7 // (C) 2004 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
33 using System.ComponentModel;
35 namespace System.Web.UI.WebControls
37 [DesignerAttribute ("System.Web.UI.Design.WebControls.HierarchicalDataBoundControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
38 public abstract class HierarchicalDataBoundControl : BaseDataBoundControl
40 [IDReferencePropertyAttribute (typeof(HierarchicalDataSourceControl))]
41 public override string DataSourceID {
43 object o = ViewState ["DataSourceID"];
51 RequiresDataBinding = true;
53 ViewState ["DataSourceID"] = value;
57 protected virtual HierarchicalDataSourceView GetData (string viewPath)
59 if (DataSource != null && DataSourceID != "")
60 throw new HttpException ();
62 IHierarchicalDataSource ds = GetDataSource ();
64 return ds.GetHierarchicalView (viewPath);
69 protected virtual IHierarchicalDataSource GetDataSource ()
71 if (DataSourceID != "")
72 return BaseDataBoundControl.FindDataSource (this, DataSourceID);
74 return DataSource as IHierarchicalDataSource;
79 return ViewState.GetBool ("DataBound", false);
82 ViewState ["DataBound"] = value;
86 protected void MarkAsDataBound ()
91 protected override void OnDataPropertyChanged ()
93 RequiresDataBinding = true;
96 protected virtual void OnDataSourceChanged (object sender, EventArgs e)
98 RequiresDataBinding = true;
101 protected internal override void OnLoad (EventArgs e)
111 private void Initialize ()
113 if (!Page.IsPostBack || (IsViewStateEnabled && !IsDataBound))
114 RequiresDataBinding = true;
116 IHierarchicalDataSource ds = GetDataSource ();
117 if (ds != null && DataSourceID != "")
118 ds.DataSourceChanged += new EventHandler (OnDataSourceChanged);
121 protected override void OnPagePreLoad (object sender, EventArgs e)
123 base.OnPagePreLoad (sender, e);
128 protected internal virtual void PerformDataBinding ()
132 protected override void PerformSelect ()
134 OnDataBinding (EventArgs.Empty);
135 PerformDataBinding ();
136 // The PerformDataBinding method has completed.
137 RequiresDataBinding = false;
139 OnDataBound (EventArgs.Empty);
142 protected override void ValidateDataSource (object dataSource)
144 if (dataSource == null || dataSource is IHierarchicalDataSource || dataSource is IHierarchicalEnumerable)
146 throw new InvalidOperationException ("Invalid data source");