context: //
  // System.Web.UI.WebControls.BaseDataList.cs
  //
  // Author:
  //	Sebastien Pouliot  <sebastien@ximian.com>
  //
  // Copyright (C) 2005-2010 Novell, Inc (http://www.novell.com)
  //
  // Permission is hereby granted, free of charge, to any person obtaining
  // a copy of this software and associated documentation files (the
  // "Software"), to deal in the Software without restriction, including
  // without limitation the rights to use, copy, modify, merge, publish,
  // distribute, sublicense, and/or sell copies of the Software, and to
  // permit persons to whom the Software is furnished to do so, subject to
  // the following conditions:
  // 
  // The above copyright notice and this permission notice shall be
  // included in all copies or substantial portions of the Software.
  // 
  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  //
  
  using System.Collections;
  using System.ComponentModel;
  using System.Security.Permissions;
  
  namespace System.Web.UI.WebControls
  {
  	// CAS
  	[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  	[AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  	// attributes
  	[DefaultEvent ("SelectedIndexChanged")]
  	[DefaultProperty ("DataSource")]
  	[Designer ("System.Web.UI.Design.WebControls.BaseDataListDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  	public abstract class BaseDataList : WebControl 
  	{
  		static readonly object selectedIndexChangedEvent = new object ();
  
  		DataKeyCollection keycoll;
  		object source;
  
  		//string dataSourceId;
  		IDataSource boundDataSource = null;
  		bool initialized;
  		bool requiresDataBinding;
  		DataSourceSelectArguments selectArguments;
  		IEnumerable data;
  
  		protected BaseDataList ()
  		{
  		}
  
  
  		[DefaultValue ("")]
  		[Localizable (true)]
  		[WebSysDescription ("")]
  		[WebCategory ("Accessibility")]
  		public virtual string Caption {
  			get { return ViewState.GetString ("Caption", String.Empty); }
  			set {
  				if (value == null)
  					ViewState.Remove ("Caption");
  				else
  					ViewState ["Caption"] = value;
  			}
  		}
  
  		[DefaultValue (TableCaptionAlign.NotSet)]
  		public virtual TableCaptionAlign CaptionAlign {
  			get { return (TableCaptionAlign) ViewState.GetInt ("CaptionAlign", (int)TableCaptionAlign.NotSet); }
  			set {
  				if ((value < TableCaptionAlign.NotSet) || (value > TableCaptionAlign.Right))
  					throw new ArgumentOutOfRangeException (Locale.GetText ("Invalid TableCaptionAlign value."));
  
  				ViewState ["CaptionAlign"] = value;
  			}
  		}
  
  		[DefaultValue (-1)]
  		[WebSysDescription("")]
  		[WebCategory("Layout")]
  		public virtual int CellPadding {
  			get {
  				if (!ControlStyleCreated)
  					return -1; // default value
  				return TableStyle.CellPadding;
  			}
  			set { TableStyle.CellPadding = value; }
  		}
  
  		[DefaultValue (0)]
  		[WebSysDescription("")]
  		[WebCategory("Layout")]
  		public virtual int CellSpacing {
  			get {
  				if (!ControlStyleCreated)
  					return 0; // default value
  				return TableStyle.CellSpacing;
  			}
  			set { TableStyle.CellSpacing = value; }
  		}
  
  		public override ControlCollection Controls {
  			get {
  				EnsureChildControls ();
  				return base.Controls;
  			}
  		}
  
  		[DefaultValue ("")]
  		[Themeable (false)]
  		[MonoTODO ("incomplete")]
  		[WebSysDescription("")]
  		[WebCategory("Data")]
  		public virtual string DataKeyField {
  			get { return ViewState.GetString ("DataKeyField", String.Empty); }
  			set {
  				if (value == null)
  					ViewState.Remove ("DataKeyField");
  				else
  					ViewState ["DataKeyField"] = value;
  			}
  		}
  
  		[Browsable (false)]
  		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  		[WebSysDescription("")]
  		[WebCategory("Data")]
  		public DataKeyCollection DataKeys {
  			get {
  				if (keycoll == null)
  					keycoll = new DataKeyCollection (DataKeysArray);
  				return keycoll;
  			}
  		}
  
  		protected ArrayList DataKeysArray {
  			get {
  				ArrayList keys = (ArrayList) ViewState ["DataKeys"];
  				if (keys == null) {
  					keys = new ArrayList ();
  					ViewState ["DataKeys"] = keys;
  				}
  				return keys;
  			}
  		}
  
  		[DefaultValue ("")]
  		[Themeable (false)]
  		[WebSysDescription("")]
  		[WebCategory("Data")]
  		public string DataMember {
  			get { return ViewState.GetString ("DataMember", String.Empty); }
  			set {
  				if (value == null)
  					ViewState.Remove ("DataMember");
  				else
  					ViewState ["DataMember"] = value;
  				OnDataPropertyChanged ();
  			}
  		}
  
  		[Bindable (true)]
  		[DefaultValue (null)]
  		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  		[Themeable (false)]
  		[WebSysDescription("")]
  		[WebCategory("Data")]
  			public virtual object DataSource {
  			get { return source; }
  			set {
  				if ((value == null) || (value is IEnumerable) || (value is IListSource)) {
  					// FIXME - can't duplicate in a test case ? LAMESPEC ?
  					// can't duplicate in a test case
  					// if ((dataSourceId != null) && (dataSourceId.Length != 0))
  					//	throw new HttpException (Locale.GetText ("DataSourceID is already set."));
  
  					source = value;
  
  					OnDataPropertyChanged ();
  
  				} else {
  					string msg = Locale.GetText ("Invalid data source. This requires an object implementing {0} or {1}.",
  								     "IEnumerable", "IListSource");
  					throw new ArgumentException (msg);
  				}
  			}
  		}
  
  		[DefaultValue (GridLines.Both)]
  		[WebSysDescription("")]
  		[WebCategory("Appearance")]
  		public virtual GridLines GridLines {
  			get {
  				if (!ControlStyleCreated)
  					return GridLines.Both; // default value
  				return TableStyle.GridLines;
  			}
  			set { TableStyle.GridLines = value; }
  		}
  
  		[Category ("Layout")]
  		[DefaultValue (HorizontalAlign.NotSet)]
  		[WebSysDescription("")]
  		public virtual HorizontalAlign HorizontalAlign {
  			get {
  				if (!ControlStyleCreated)
  					return HorizontalAlign.NotSet; // default value
  				return TableStyle.HorizontalAlign;
  			}
  			set { TableStyle.HorizontalAlign = value; }
  		}
  
  		[DefaultValue (false)]
  		public virtual bool UseAccessibleHeader {
  			get { return ViewState.GetBool ("UseAccessibleHeader", false); }
  			set { ViewState ["UseAccessibleHeader"] = value; }
  		}
  
  		[DefaultValue ("")]
  
gt: 		[IDReferenceProperty (typeof (DataSourceControl))]