3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 * Namespace: System.Web.UI.Design.WebControls
24 * Class: BaseDataListDesigner
26 * Author: Gaurav Vaish
27 * Maintainer: mastergaurav AT users DOT sf DOT net
29 * (C) Gaurav Vaish (2002)
33 using System.Collections;
34 using System.ComponentModel;
35 using System.ComponentModel.Design;
36 using System.Reflection;
37 using System.Web.UI.Design;
39 using System.Web.UI.WebControls;
42 namespace System.Web.UI.Design.WebControls
44 public abstract class BaseDataListDesigner : TemplatedControlDesigner,
47 private BaseDataList baseDataList;
48 private DataTable desTimeDataTable;
49 private DataTable dummyDataTable;
51 private static readonly string[] validNames = new string[] {
52 "AlternatingItemStyle",
66 public BaseDataListDesigner()
70 public string DataKeyField
74 return baseDataList.DataKeyField;
78 baseDataList.DataKeyField = value;
82 public string DataMember
86 return baseDataList.DataMember;
90 baseDataList.DataMember = value;
94 public string DataSource
98 DataBinding element = DataBindings["DataSource"];
101 return element.Expression;
107 if(value == null && value.Length == 0)
109 DataBindings.Remove("DataSource");
112 DataBinding element = DataBindings["DataSource"];
115 element = new DataBinding("DataSource",
120 element.Expression = value;
122 DataBindings.Add(element);
124 OnDataSourceChanged();
125 OnBindingsCollectionChanged("DataSource");
129 protected internal virtual void OnDataSourceChanged()
131 desTimeDataTable = null;
134 public override bool DesignTimeHtmlRequiresLoadComplete
138 return (DataSource.Length > 0);
142 public override DesignerVerbCollection Verbs
146 throw new NotImplementedException();
150 public object GetSelectedDataSource()
152 object retVal = null;
153 DataBinding element = DataBindings["DataSource"];
156 retVal = DesignTimeData.GetSelectedDataSource(baseDataList,
162 public IEnumerable GetResolvedSelectedDataSource()
164 IEnumerable retVal = null;
165 DataBinding element = DataBindings["DataSource"];
168 retVal = DesignTimeData.GetSelectedDataSource(baseDataList,
175 public override IEnumerable GetTemplateContainerDataSource(
178 return GetResolvedSelectedDataSource();
181 public override void Initialize(IComponent component)
183 baseDataList = (BaseDataList)component;
184 base.Initialize(component);
187 public override void OnComponentChanged(object sender,
188 ComponentChangedEventArgs e)
192 string name = e.Member.Name;
193 foreach(string current in validNames)
202 base.OnComponentChanged(sender, e);
205 protected internal void OnStylesChanged()
207 OnTemplateEditingVerbsChanged();
210 protected abstract void OnTemplateEditingVerbsChanged();
212 protected override void Dispose(bool disposing)
216 base.Dispose(disposing);
219 protected IEnumerable GetDesignTimeDataSource(int minimumRows,
220 out bool dummyDataSource)
222 return GetDesignTimeDataSource(GetResolvedSelectedDataSource(),
224 out dummyDataSource);
227 protected IEnumerable GetDesignTimeDataSource(IEnumerable selectedDataSource,
229 out bool dummyDataSource)
231 DataTable toDeploy = desTimeDataTable;
232 dummyDataSource = false;
235 if(selectedDataSource != null)
237 desTimeDataTable = DesignTimeData.CreateSampleDataTable(
239 toDeploy = desTimeDataTable;
243 if(dummyDataTable == null)
244 dummyDataTable = DesignTimeData.CreateDummyDataTable();
245 toDeploy = dummyDataTable;
246 dummyDataSource = true;
249 return DesignTimeData.GetDesignTimeDataSource(toDeploy, minimumRows);