2 * Namespace: System.Web.UI.WebControls
\r
3 * Class: BaseDataList
\r
5 * Author: Gaurav Vaish
\r
6 * Maintainer: gvaish@iitk.ac.in
\r
7 * Contact: <my_scripts2001@yahoo.com>, <gvaish@iitk.ac.in>
\r
8 * Implementation: yes
\r
11 * (C) Gaurav Vaish (2001)
\r
15 using System.Collections;
\r
17 using System.Web.UI;
\r
19 namespace System.Web.UI.WebControls
\r
21 public abstract class BaseDataList: WebControl
\r
23 private static readonly object SelectedIndexChangedEvent = new object();
\r
24 internal static string ItemCountViewStateKey = "_!ItemCount";
\r
26 private DataKeyCollection dataKeys;
\r
27 private object dataSource;
\r
29 public BaseDataList() : base();
\r
33 public static bool IsBindableType(Type type)
\r
35 if(type.IsPrimitive || type == typeof(string) || type == typeof(DateTime) || type == typeof(Decimal))
\r
40 public override void DataBind()
\r
42 OnDataBinding(EventArgs.Empty);
\r
45 public event EventHandler SelectedIndexChanged
\r
49 Events.AddHandler(SelectedIndexChangedEvent, value);
\r
53 Events.RemoveHandler(SelectedIndexChangedEvent, value);
\r
57 public virtual int CellPadding
\r
61 if(!ControlStyleCreated)
\r
63 return ((TableStyle)ControlStyle).CellPadding;
\r
67 ((TableStyle)ControlStyle).CellPadding = value;
\r
71 public virtual int CellSpacing
\r
75 if(!ControlStyleCreated)
\r
77 return ((TableStyle)ControlStyle).CellSpacing;
\r
81 ((TableStyle)ControlStyle).CellSpacing = value;
\r
85 public virtual string DataKeyField
\r
89 object o = ViewState["DataKeyField"];
\r
92 return String.Empty;
\r
96 ViewState["DataKeyField"] = value;
\r
100 public DataKeyCollection DataKeys
\r
105 dataKeys = new DataKeyCollection(DataKeysArray);
\r
111 public string DataMember
\r
115 object o = ViewState["DataMember"];
\r
118 return String.Empty;
\r
122 ViewState["DataMember"] = value;
\r
126 public virtual object DataSource
\r
134 if( (value) && ( value is IListSource || value is IEnumerable) )
\r
136 dataSource = value;
\r
139 throw new ArgumentException(HttpRuntime.FormatResourceString("Invalid_DataSource_Type", ID));
\r
144 public virtual GridLines GridLines
\r
148 if(ControlStyleCreated)
\r
149 return ((TableStyle)ControlStyle).GridLines;
\r
150 return GridLines.Both;
\r
154 ((TableStyle)ControlStyle).GridLines = value;
\r
158 public virtual HorizontalAlign HorizontalAlign
\r
162 if(ControlStyleCreated)
\r
163 return ((TableStyle)ControlStyle).HorizontalAlign;
\r
164 return HorizontalAlign.NotSet;
\r
168 ((TableStyle)ControlStyle).HorizontalAlign = value;
\r
172 protected ArrayList DataKeysArray
\r
176 object o = ViewState["DataKeys"];
\r
179 o = new ArrayList();
\r
180 ViewState["DataKeys"] = o;
\r
182 return (ArrayList)o;
\r
186 protected override void AddParsedSubObject(object o)
\r
188 // Preventing literal controls from being added as children.
\r
191 protected override void CreateChildControls()
\r
194 if(ViewState[ItemCountViewStateKey]!=null)
\r
196 CreateControlHierarchy(true);
\r
197 ClearChildViewState();
\r
201 protected override void OnDataBinding(EventArgs e)
\r
203 base.OnDataBinding(e);
\r
205 ClearChildViewState();
\r
206 CreateControlHierarchy(true);
\r
207 ChildControlsCreated = true;
\r
211 protected virtual void OnSelectedIndexChanged(EventArgs e)
\r
215 EventHandler eh = (EventHandler)(Events[SelectedIndexChangedEvent]);
\r
221 protected override void Render(HtmlTextWriter writer)
\r
223 PrepareControlHierarchy();
\r
224 base.RenderContents(writer);
\r
227 protected abstract void PrepareControlHierarchy();
\r
228 protected abstract void CreateControlHierarchy(bool useDataSource);
\r