[DefaultPropertyAttribute ("DataSource")]
#endif
[Designer("System.Web.UI.Design.WebControls.ListControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
+ [ParseChildrenAttribute (true, "Items")]
#if NET_2_0
[ControlValueProperty ("SelectedValue", null)]
- [ParseChildrenAttribute (true, "Items", ChildControlType = typeof (Control))]
-#else
- [ParseChildrenAttribute (true, "Items")]
#endif
public abstract class ListControl :
#if NET_2_0
[WebCategory ("Data")]
public virtual object DataSource {
get { return data_source; }
- set { data_source = value; }
+ set {
+ if(value == null || value is IListSource || value is IEnumerable) {
+ data_source = value;
+ return;
+ }
+ throw new ArgumentException("Invalid DataSource Type");
+ }
}
#endif
return -1;
}
set {
- ClearSelection ();
- if (value == -1)
- return;
-
if (items == null || items.Count == 0) {
// This will happen when assigning this property
// before DataBind () is called on the control.
return;
}
- if (value < 0 || value >= Items.Count)
+ if (value < -1 || value >= Items.Count)
throw new ArgumentOutOfRangeException ("value");
+
+ ClearSelection ();
+ if (value == -1)
+ return;
+
items [value].Selected = true;
/* you'd think this would be called, but noooo */
items [i].Selected = false;
}
-#if NET_2_0
- protected internal override void LoadControlState (object savedState)
- {
- object first = null;
- ArrayList indices = null;
- Pair pair = savedState as Pair;
-
- if (pair != null) {
- first = pair.First;
- indices = pair.Second as ArrayList;
- }
-
- base.LoadControlState (first);
-
- if (indices != null) {
- foreach (int index in indices)
- Items [index].Selected = true;
- }
- }
-#endif
-
protected override void OnDataBinding (EventArgs e)
{
base.OnDataBinding (e);
if (list == null)
return;
- Items.Clear ();
-
- string format = DataTextFormatString;
- if (format == "")
- format = null;
-
- string text_field = DataTextField;
- string value_field = DataValueField;
- ListItemCollection coll = Items;
- foreach (object container in list) {
- string text;
- string val;
-
- text = val = null;
- if (text_field != "") {
- text = DataBinder.GetPropertyValue (container, text_field, format);
- }
-
- if (value_field != "") {
- val = DataBinder.GetPropertyValue (container, value_field).ToString ();
- } else if (text_field == "") {
- text = val = container.ToString ();
- if (format != null)
- text = String.Format (format, container);
- } else if (text != null) {
- val = text;
- }
-
- if (text == null)
- text = val;
-
- coll.Add (new ListItem (text, val));
- }
+#if NET_2_0
+ if (!AppendDataBoundItems)
+#endif
+ Items.Clear();
+#if !NET_2_0
+ DoDataBinding (list);
+#endif
if (saved_selected_value != null) {
SelectedValue = saved_selected_value;
if (saved_selected_index != -2 && saved_selected_index != SelectedIndex)
}
}
-#if NET_2_0
- protected internal override void OnInit (EventArgs e)
- {
- Page.RegisterRequiresControlState (this);
- base.OnInit (e);
- }
-#endif
-
#if NET_2_0
protected internal
#else
base.OnPreRender (e);
}
+ void DoDataBinding (IEnumerable dataSource)
+ {
+ if (dataSource != null) {
+ string format = DataTextFormatString;
+ if (format == "")
+ format = null;
+
+ string text_field = DataTextField;
+ string value_field = DataValueField;
+ ListItemCollection coll = Items;
+ foreach (object container in dataSource) {
+ string text;
+ string val;
+
+ text = val = null;
+ if (text_field != "") {
+ text = DataBinder.GetPropertyValue (container, text_field, format);
+ }
+
+ if (value_field != "") {
+ val = DataBinder.GetPropertyValue (container, value_field).ToString ();
+ } else if (text_field == "") {
+ text = val = container.ToString ();
+ if (format != null)
+ text = String.Format (format, container);
+ } else if (text != null) {
+ val = text;
+ }
+
+ if (text == null)
+ text = val;
+
+ coll.Add (new ListItem (text, val));
+ }
+ }
+ }
+
#if NET_2_0
protected virtual void OnTextChanged (EventArgs e)
{
handler (this, e);
}
- [MonoTODO]
protected internal override void PerformDataBinding (IEnumerable dataSource)
{
- throw new NotImplementedException ();
+ base.PerformDataBinding (dataSource);
+
+ DoDataBinding (dataSource);
}
- [MonoTODO]
+ [MonoTODO ("why override?")]
protected override void PerformSelect ()
{
- throw new NotImplementedException ();
+ base.PerformSelect ();
}
[MonoTODO]
base.RenderContents (w);
}
- protected internal override object SaveControlState ()
- {
- object first;
- ArrayList second;
-
- first = base.SaveControlState ();
- second = GetSelectedIndicesInternal ();
- if (second == null)
- second = new ArrayList();
-
- return new Pair (first, second);
- }
#endif
internal ArrayList GetSelectedIndicesInternal ()
if (manager != null)
second = manager.SaveViewState ();
-#if !NET_2_0
ArrayList selected = GetSelectedIndicesInternal ();
-#endif
- if (first == null && second == null
-#if !NET_2_0
- && selected == null
-#endif
- )
+ if (first == null && second == null && selected == null)
return null;
-#if NET_2_0
- return new Pair (first, second);
-#else
return new Triplet (first, second, selected);
-#endif
}
protected override void LoadViewState (object savedState)
{
object first = null;
object second = null;
-#if !NET_2_0
ArrayList indices = null;
-#endif
-#if NET_2_0
- Pair pair = savedState as Pair;
- if (pair != null) {
- first = pair.First;
- second = pair.Second;
- }
-#else
Triplet triplet = savedState as Triplet;
if (triplet != null) {
first = triplet.First;
second = triplet.Second;
indices = triplet.Third as ArrayList;
}
-#endif
base.LoadViewState (first);
manager.LoadViewState (second);
}
-#if !NET_2_0
if (indices != null) {
foreach (int index in indices)
Items [index].Selected = true;
}
-#endif
}
#if NET_2_0
}
- [MonoTODO]
[Themeable (false)]
[DefaultValue (false)]
[WebSysDescription ("")]
[WebCategory ("Behavior")]
- public virtual bool CausesValidation {
+ public virtual bool CausesValidation {
get {
- throw new NotImplementedException ();
+ return ViewState.GetBool ("CausesValidation", false);
}
+
set {
- throw new NotImplementedException ();
+ ViewState ["CausesValidation"] = value;
}
}
- [MonoTODO]
[Themeable (false)]
[DefaultValue ("")]
[WebSysDescription ("")]
[WebCategoryAttribute ("Behavior")]
public virtual string ValidationGroup {
get {
- throw new NotImplementedException ();
+ return ViewState.GetString ("ValidationGroup", "");
}
set {
- throw new NotImplementedException ();
+ ViewState ["ValidationGroup"] = value;
}
}