2 // System.Web.UI.WebControls.BaseDataBoundControl.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;
34 namespace System.Web.UI.WebControls
36 public abstract class BaseDataBoundControl: WebControl
38 public event EventHandler DataBound;
43 bool requiresDataBinding = true;
45 public virtual object DataSource {
50 ValidateDataSource (value);
55 public virtual string DataSourceID {
56 get { return dataSourceId; }
57 set { dataSourceId = value; }
60 protected bool Initialized {
61 get { return initialized; }
65 protected bool IsBoundUsingDataSourceID {
66 get { return dataSourceId != null; }
69 protected bool RequiresDataBinding {
70 get { return requiresDataBinding; }
71 set { requiresDataBinding = value; }
75 protected void ConfirmInitState ()
79 public override void DataBind ()
82 RequiresDataBinding = false;
83 OnDataBound (EventArgs.Empty);
86 protected void EnsureDataBound ()
88 if (RequiresDataBinding && DataSourceID != "")
92 protected virtual void OnDataBound (EventArgs e)
94 if (DataBound != null)
99 protected virtual void OnDataPropertyChanged ()
104 protected override void OnInit (EventArgs e)
108 if (!Page.IsPostBack)
109 RequiresDataBinding = true;
113 protected virtual void OnPagePreLoad (object sender, EventArgs e)
117 protected override void OnPreRender (EventArgs e)
120 base.OnPreRender (e);
123 protected abstract void PerformSelect ();
125 protected abstract void ValidateDataSource (object dataSource);