Browse Source

2005-04-01 Lluis Sanchez Gual <[email protected]>

	* ButtonField.cs: Mostly implemented.
	* DataControlFieldHeaderCell.cs: Implemented.
	* ObjectDataSourceView.cs: Initial implementation.
	* DataControlButton.cs: Added support for real buttons.
	* Label.cs, DataControlField.cs: Flush.
	* ObjectDataSource.cs: Initial implementation.
	* HiddenField.cs: Added class stub.
	* GridView.cs: Load autogenerated field properties before
	creating the children, to make sure that column info is ready.
	* ControlParameter.cs: Implemented Evaluate method.
	* ImageField.cs: Added class stub.
	* BoundField.cs: Added HtmlEncode property.
	* DataControlFieldCell.cs: Moved AccessibleDataControlFieldCell
	to its own file.
	* CheckBoxField.cs: Mostly implemented.
	* TemplateField.cs: Added class stub.
	* ObjectDataSourceSelectingEventArgs.cs: Added missing property.
	* ObjectDataSourceMethodEventArgs.cs: Fixed base class.
	* Parameter.cs: Added internal GetValue method (Evaluate is protected)


svn path=/trunk/mcs/; revision=42469
Lluis Sanchez 21 năm trước cách đây
mục cha
commit
eefe5a8604
19 tập tin đã thay đổi với 1443 bổ sung74 xóa
  1. 30 10
      mcs/class/System.Web/System.Web.UI.WebControls/BoundField.cs
  2. 187 0
      mcs/class/System.Web/System.Web.UI.WebControls/ButtonField.cs
  3. 22 0
      mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
  4. 118 0
      mcs/class/System.Web/System.Web.UI.WebControls/CheckBoxField.cs
  5. 11 2
      mcs/class/System.Web/System.Web.UI.WebControls/ControlParameter.cs
  6. 49 21
      mcs/class/System.Web/System.Web.UI.WebControls/DataControlButton.cs
  7. 8 3
      mcs/class/System.Web/System.Web.UI.WebControls/DataControlField.cs
  8. 0 19
      mcs/class/System.Web/System.Web.UI.WebControls/DataControlFieldCell.cs
  9. 68 0
      mcs/class/System.Web/System.Web.UI.WebControls/DataControlFieldHeaderCell.cs
  10. 16 15
      mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs
  11. 40 0
      mcs/class/System.Web/System.Web.UI.WebControls/HiddenField.cs
  12. 40 0
      mcs/class/System.Web/System.Web.UI.WebControls/ImageField.cs
  13. 1 1
      mcs/class/System.Web/System.Web.UI.WebControls/Label.cs
  14. 219 0
      mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSource.cs
  15. 1 1
      mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSourceMethodEventArgs.cs
  16. 8 2
      mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSourceSelectingEventArgs.cs
  17. 580 0
      mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSourceView.cs
  18. 5 0
      mcs/class/System.Web/System.Web.UI.WebControls/Parameter.cs
  19. 40 0
      mcs/class/System.Web/System.Web.UI.WebControls/TemplateField.cs

+ 30 - 10
mcs/class/System.Web/System.Web.UI.WebControls/BoundField.cs

@@ -114,6 +114,18 @@ namespace System.Web.UI.WebControls {
 				ViewState ["ReadOnly"] = value;
 			}
 		}
+
+		[WebCategoryAttribute ("HtmlEncode")]
+		[DefaultValueAttribute (true)]
+		public virtual bool HtmlEncode {
+			get {
+				object val = ViewState ["HtmlEncode"];
+				return val != null ? (bool) val : true;
+			}
+			set { 
+				ViewState ["HtmlEncode"] = true;
+			}
+		}
 		
 		public override void ExtractValuesFromCell (IOrderedDictionary dictionary,
 			DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly)
@@ -145,27 +157,35 @@ namespace System.Web.UI.WebControls {
 			}
 		}
 		
-		string FormatValue (object value)
+		protected virtual bool SupportsHtmlEncode {
+			get { return true; }
+		}
+		
+		protected virtual string FormatDataValue (object value, bool encode)
 		{
+			string res;
 			if (value == null || (value.ToString().Length == 0 && ConvertEmptyStringToNull))
-				return NullDisplayText;
-			if (DataFormatString.Length > 0)
-				return string.Format (DataFormatString, value);
+				res = NullDisplayText;
+			else if (DataFormatString.Length > 0)
+				res = string.Format (DataFormatString, value);
 			else
-				return value.ToString ();
+				res = value.ToString ();
+				
+			if (encode) return HttpUtility.HtmlEncode (res);
+			else return res;
 		}
 		
 		protected virtual object GetValue (Control controlContainer)
 		{
 			if (DesignMode)
-				return GetDesignTimeValue (controlContainer);
+				return GetDesignTimeValue ();
 			else
 				return GetBoundValue (controlContainer);
 		}
 		
-		protected virtual object GetDesignTimeValue (Control controlContainer)
+		protected virtual object GetDesignTimeValue ()
 		{
-			return GetBoundValue (controlContainer);
+			return GetBoundValue (Control);
 		}
 		
 		object GetBoundValue (Control controlContainer)
@@ -196,10 +216,10 @@ namespace System.Web.UI.WebControls {
 			DataControlFieldCell cell = (DataControlFieldCell) sender;
 			if (cell.Controls.Count > 0) {
 				TextBox box = cell.Controls [0] as TextBox;
-				box.Text = FormatValue (GetValue (cell.BindingContainer));
+				box.Text = FormatDataValue (GetValue (cell.BindingContainer), SupportsHtmlEncode && HtmlEncode);
 			}
 			else
-				cell.Text = FormatValue (GetValue (cell.BindingContainer));
+				cell.Text = FormatDataValue (GetValue (cell.BindingContainer), SupportsHtmlEncode && HtmlEncode);
 		}
 	}
 }

+ 187 - 0
mcs/class/System.Web/System.Web.UI.WebControls/ButtonField.cs

@@ -0,0 +1,187 @@
+//
+// System.Web.UI.WebControls.ButtonField.cs
+//
+// Authors:
+//	Lluis Sanchez Gual ([email protected])
+//
+// (C) 2005 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.
+//
+
+#if NET_2_0
+using System.Reflection;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Web.UI;
+using System.ComponentModel;
+using System.Security.Permissions;
+
+namespace System.Web.UI.WebControls {
+
+	[AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+	[AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+	public class ButtonField : ButtonFieldBase
+	{
+		PropertyDescriptor boundProperty;
+
+	    [WebCategoryAttribute ("Behavior")]
+	    [DefaultValueAttribute ("")]
+		public virtual string CommandName {
+			get {
+				object ob = ViewState ["CommandName"];
+				if (ob != null) return (string) ob;
+				return "";
+			}
+			set {
+				ViewState ["CommandName"] = value;
+				OnFieldChanged ();
+			}
+		}
+		
+	    [WebCategoryAttribute ("Data")]
+	    [DefaultValueAttribute ("")]
+		public virtual string DataTextField {
+			get {
+				object ob = ViewState ["DataTextField"];
+				if (ob != null) return (string) ob;
+				return "";
+			}
+			set {
+				ViewState ["DataTextField"] = value;
+				OnFieldChanged ();
+			}
+		}
+		
+	    [WebCategoryAttribute ("Data")]
+	    [DefaultValueAttribute ("")]
+		public virtual string DataTextFormatString {
+			get {
+				object ob = ViewState ["DataTextFormatString"];
+				if (ob != null) return (string) ob;
+				return "";
+			}
+			set {
+				ViewState ["DataTextFormatString"] = value;
+				OnFieldChanged ();
+			}
+		}
+		
+		[EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
+	    [WebCategoryAttribute ("Appearance")]
+	    [DefaultValueAttribute ("")]
+	    [UrlPropertyAttribute]
+		public virtual string ImageUrl {
+			get {
+				object ob = ViewState ["ImageUrl"];
+				if (ob != null) return (string) ob;
+				return "";
+			}
+			set {
+				ViewState ["ImageUrl"] = value;
+				OnFieldChanged ();
+			}
+		}
+		
+	    [LocalizableAttribute (true)]
+	    [WebCategoryAttribute ("Appearance")]
+	    [DefaultValueAttribute ("")]
+		public virtual string Text {
+			get {
+				object ob = ViewState ["Text"];
+				if (ob != null) return (string) ob;
+				return "";
+			}
+			set {
+				ViewState ["Text"] = value;
+				OnFieldChanged ();
+			}
+		}
+		
+		public override bool Initialize (bool sortingEnabled, Control control)
+		{
+			return base.Initialize (sortingEnabled, control);
+		}
+		
+		protected virtual string FormatDataTextValue (object value)
+		{
+			if (DataTextFormatString.Length > 0)
+				return string.Format (DataTextFormatString, value);
+			else if (value == null)
+				return string.Empty;
+			else
+				return value.ToString ();
+		}
+		
+		public override void InitializeCell (DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
+		{
+			string index = rowIndex.ToString ();
+			
+			if (cellType == DataControlCellType.DataCell) {
+				DataControlButton btn = new DataControlButton (Control);
+				btn.CommandName = CommandName;
+				btn.CommandArgument = index;
+				
+				if (DataTextField != "") {
+					cell.DataBinding += new EventHandler (OnDataBindField);
+				}
+				else {
+					btn.Text = Text;
+					btn.ButtonType = ButtonType;
+					if (ButtonType == ButtonType.Image) btn.ImageUrl = ImageUrl;
+				}
+				cell.Controls.Add (btn);
+			}
+			else
+				base.InitializeCell (cell, cellType, rowState, rowIndex);
+		}
+		
+		protected virtual void OnDataBindField (object sender, EventArgs e)
+		{
+			DataControlFieldCell cell = (DataControlFieldCell) sender;
+			DataControlButton btn = (DataControlButton) cell.Controls [0]; 
+			btn.Text = FormatDataTextValue (GetBoundValue (cell.BindingContainer));
+			if (ButtonType == ButtonType.Image) btn.ImageUrl = ImageUrl;
+			btn.ButtonType = ButtonType;
+		}
+		
+		object GetBoundValue (Control controlContainer)
+		{
+			IDataItemContainer dic = controlContainer as IDataItemContainer;
+			if (boundProperty == null) {
+				ICustomTypeDescriptor desc = dic.DataItem as ICustomTypeDescriptor;
+				if (desc != null) {
+					boundProperty = desc.GetProperties () [DataTextField];
+					if (boundProperty != null)
+						return boundProperty.GetValue (dic.DataItem);
+				} else {
+					PropertyInfo pi = dic.DataItem.GetType ().GetProperty (DataTextField);
+					if (pi != null)
+						return pi.GetValue (dic.DataItem, null);
+				}
+				throw new InvalidOperationException ("Property '" + DataTextField + "' not found in data bound item");
+			}
+			return boundProperty.GetValue (dic.DataItem);
+		}
+	}
+}
+#endif

+ 22 - 0
mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog

@@ -1,3 +1,25 @@
+2005-04-01  Lluis Sanchez Gual <[email protected]>
+
+	* ButtonField.cs: Mostly implemented.
+	* DataControlFieldHeaderCell.cs: Implemented.
+	* ObjectDataSourceView.cs: Initial implementation.
+	* DataControlButton.cs: Added support for real buttons.
+	* Label.cs, DataControlField.cs: Flush.
+	* ObjectDataSource.cs: Initial implementation.
+	* HiddenField.cs: Added class stub.
+	* GridView.cs: Load autogenerated field properties before
+	creating the children, to make sure that column info is ready.
+	* ControlParameter.cs: Implemented Evaluate method.
+	* ImageField.cs: Added class stub.
+	* BoundField.cs: Added HtmlEncode property.
+	* DataControlFieldCell.cs: Moved AccessibleDataControlFieldCell
+	to its own file.
+	* CheckBoxField.cs: Mostly implemented.
+	* TemplateField.cs: Added class stub.
+	* ObjectDataSourceSelectingEventArgs.cs: Added missing property.
+	* ObjectDataSourceMethodEventArgs.cs: Fixed base class.
+	* Parameter.cs: Added internal GetValue method (Evaluate is protected)
+
 2005-03-23  Lluis Sanchez Gual <[email protected]>
 
 	* DataControlField.cs: Added missing InsertVisible property.

+ 118 - 0
mcs/class/System.Web/System.Web.UI.WebControls/CheckBoxField.cs

@@ -0,0 +1,118 @@
+//
+// System.Web.UI.WebControls.CheckBoxField.cs
+//
+// Authors:
+//	Lluis Sanchez Gual ([email protected])
+//
+// (C) 2005 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.
+//
+
+#if NET_2_0
+using System.Collections;
+using System.Collections.Specialized;
+using System.Web.UI;
+using System.ComponentModel;
+using System.Security.Permissions;
+
+namespace System.Web.UI.WebControls {
+
+	[AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+	[AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+	public class CheckBoxField : BoundField
+	{
+		public override bool ConvertEmptyStringToNull {
+			get { throw GetNotSupportedPropException ("ConvertEmptyStringToNull"); } 
+			set { throw GetNotSupportedPropException ("ConvertEmptyStringToNull"); } 
+		}
+		
+		public override string DataFormatString {
+			get { throw GetNotSupportedPropException ("DataFormatString"); } 
+			set { throw GetNotSupportedPropException ("DataFormatString"); } 
+		}
+		
+		public override bool HtmlEncode {
+			get { throw GetNotSupportedPropException ("HtmlEncode"); } 
+			set { throw GetNotSupportedPropException ("HtmlEncode"); } 
+		}
+		
+		public override string NullDisplayText {
+			get { throw GetNotSupportedPropException ("NullDisplayText"); } 
+			set { throw GetNotSupportedPropException ("NullDisplayText"); } 
+		}
+		
+		protected override bool SupportsHtmlEncode {
+			get { return false; }
+		}
+		
+	    [WebCategoryAttribute ("Appearance")]
+	    [LocalizableAttribute (true)]
+	    [DefaultValueAttribute ("")]
+		public virtual string Text {
+			get {
+				object ob = ViewState ["Text"];
+				if (ob != null) return (string) ob;
+				return "";
+			}
+			set {
+				ViewState ["Text"] = value;
+				OnFieldChanged ();
+			}
+		}
+		
+		public override void InitializeDataCell (DataControlFieldCell cell, DataControlRowState rowState)
+		{
+			bool editable = (rowState & DataControlRowState.Edit) != 0;
+			CheckBox box = new CheckBox ();
+			box.Enabled = editable && !ReadOnly;
+			cell.Controls.Add (box);
+		}
+		
+		public override void ExtractValuesFromCell (IOrderedDictionary dictionary,
+			DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly)
+		{
+			CheckBox box = (CheckBox) cell.Controls [0];
+			dictionary [DataField] = box.Checked;
+		}
+		
+		protected override void OnDataBindField (object sender, EventArgs e)
+		{
+			DataControlFieldCell cell = (DataControlFieldCell) sender;
+			CheckBox box = (CheckBox) cell.Controls [0];
+			object val = GetValue (cell.BindingContainer);
+			if (val != null) {
+				box.Checked = (bool)val;
+				if (!box.Visible)
+					box.Visible = true;
+			}
+			else
+				box.Visible = false;
+		}
+		
+		protected override object GetDesignTimeValue ()
+		{
+			return true;
+		}
+	}
+}
+#endif

+ 11 - 2
mcs/class/System.Web/System.Web.UI.WebControls/ControlParameter.cs

@@ -33,6 +33,7 @@ using System.Collections;
 using System.Collections.Specialized;
 using System.Text;
 using System.ComponentModel;
+using System.Reflection;
 
 namespace System.Web.UI.WebControls {
 
@@ -71,10 +72,18 @@ namespace System.Web.UI.WebControls {
 			return new ControlParameter (this);
 		}
 		
-		[MonoTODO]
 		protected override object Evaluate (HttpContext ctx, Control control)
 		{
-			throw new NotImplementedException ();
+			if (control == null) return null;
+			if (control.Page == null) return null;
+			
+			Control c = control.Page.FindControl (ControlID);
+			if (c == null) throw new HttpException ("Control '" + ControlID + "' not found.");
+			
+			PropertyInfo prop = c.GetType().GetProperty (PropertyName);
+			if (prop == null) throw new HttpException ("Property '" + PropertyName + "' not found in type '" + c.GetType() + "'.");
+			
+			return prop.GetValue (c, null);
 		}
 		
 		[WebCategoryAttribute ("Control")]

+ 49 - 21
mcs/class/System.Web/System.Web.UI.WebControls/DataControlButton.cs

@@ -42,6 +42,7 @@ namespace System.Web.UI.WebControls
 		
 		public DataControlButton (Control container)
 		{
+			this.container = container;
 		}
 		
 		public DataControlButton (Control container, string text, string image, string command, string commandArg, bool allowCallback)
@@ -76,14 +77,25 @@ namespace System.Web.UI.WebControls
 			}
 		}
 		
+		public virtual ButtonType ButtonType {
+			get {
+				object ob = ViewState ["ButtonType"];
+				if (ob != null) return (ButtonType) ob;
+				return ButtonType.Link;
+			}
+			set {
+				ViewState ["ButtonType"] = value;
+			}
+		}
+
 		protected override void Render (HtmlTextWriter writer)
 		{
-			if (CommandName.Length > 0)
+			if (CommandName.Length > 0 || ButtonType == ButtonType.Button)
 			{
 				string postScript = null;
 				string callScript = null;
 				
-				IPostBackContainer pcner = container as IPostBackContainer;
+				IPostBackContainer pcner = container as IPostBackContainer;
 				if (pcner != null) {
 					PostBackOptions ops = pcner.GetPostBackOptions (this);
 					postScript = container.Page.ClientScript.GetPostBackEventReference (ops);
@@ -99,30 +111,46 @@ namespace System.Web.UI.WebControls
 					if (ccner != null)
 						callScript = ccner.GetCallbackScript (this, CommandName + "$" + CommandArgument);
 				}
-			
-				if (ImageUrl.Length > 0) {
-					writer.AddAttribute (HtmlTextWriterAttribute.Type, "image");
-					writer.AddAttribute (HtmlTextWriterAttribute.Src, ResolveUrl (ImageUrl));
+			
+				if (ButtonType == ButtonType.Link || ButtonType == ButtonType.Image)
+				{
+					if (ImageUrl.Length > 0) {
+						writer.AddAttribute (HtmlTextWriterAttribute.Type, "image");
+						writer.AddAttribute (HtmlTextWriterAttribute.Src, ResolveUrl (ImageUrl));
+						if (callScript != null)
+							writer.AddAttribute (HtmlTextWriterAttribute.Onclick, callScript);
+						else
+							writer.AddAttribute (HtmlTextWriterAttribute.Onclick, postScript);
+						if (Text.Length > 0)
+							writer.AddAttribute (HtmlTextWriterAttribute.Alt, Text);
+						writer.RenderBeginTag (HtmlTextWriterTag.Input);
+						writer.RenderEndTag ();
+					}
+					else {
+						if (callScript != null) {
+							writer.AddAttribute (HtmlTextWriterAttribute.Onclick, callScript);
+							writer.AddAttribute (HtmlTextWriterAttribute.Href, "javascript:");
+						}
+						else
+							writer.AddAttribute (HtmlTextWriterAttribute.Href, postScript);
+						writer.RenderBeginTag (HtmlTextWriterTag.A);
+						writer.Write (Text);
+						writer.RenderEndTag ();
+					}
+				}
+				else if (ButtonType == ButtonType.Button)
+				{
 					if (callScript != null)
 						writer.AddAttribute (HtmlTextWriterAttribute.Onclick, callScript);
 					else
-						writer.AddAttribute (HtmlTextWriterAttribute.Onclick, postScript);
-					if (Text.Length > 0)
-						writer.AddAttribute (HtmlTextWriterAttribute.Alt, Text);
+						writer.AddAttribute (HtmlTextWriterAttribute.Onclick, postScript);
+						
+					writer.AddAttribute (HtmlTextWriterAttribute.Type, "submit");
+					writer.AddAttribute (HtmlTextWriterAttribute.Name, ClientID);
+					writer.AddAttribute (HtmlTextWriterAttribute.Value, Text);
 					writer.RenderBeginTag (HtmlTextWriterTag.Input);
 					writer.RenderEndTag ();
 				}
-				else {
-					if (callScript != null) {
-						writer.AddAttribute (HtmlTextWriterAttribute.Onclick, callScript);
-						writer.AddAttribute (HtmlTextWriterAttribute.Href, "javascript:");
-					}
-					else
-						writer.AddAttribute (HtmlTextWriterAttribute.Href, postScript);
-					writer.RenderBeginTag (HtmlTextWriterTag.A);
-					writer.Write (Text);
-					writer.RenderEndTag ();
-				}
 			} else {
 				if (ImageUrl.Length > 0) {
 					writer.AddAttribute (HtmlTextWriterAttribute.Src, ResolveUrl (ImageUrl));
@@ -133,7 +161,7 @@ namespace System.Web.UI.WebControls
 				}
 				else {
 					writer.Write (Text);
-				}
+				}
 			}
 		}
 	}

+ 8 - 3
mcs/class/System.Web/System.Web.UI.WebControls/DataControlField.cs

@@ -84,11 +84,11 @@ namespace System.Web.UI.WebControls {
 		{
 			if (cellType == DataControlCellType.Header && ShowHeader)
 			{
-				if (HeaderText != "" || HeaderImageUrl != "") {
-					if (sortingEnabled)
+				if (HeaderText.Length > 0 || HeaderImageUrl.Length > 0) {
+					if (sortingEnabled && SortExpression.Length > 0)
 						cell.Controls.Add (new DataControlButton (control, HeaderText, HeaderImageUrl, "Sort", SortExpression, true));
 					else
-						cell.Controls.Add (new DataControlButton (control, HeaderText, HeaderImageUrl, "", "", true));
+						cell.Controls.Add (new DataControlButton (control, HeaderText, HeaderImageUrl, string.Empty, string.Empty, true));
 				}
 			}
 			else if (cellType == DataControlCellType.Footer) {
@@ -169,6 +169,11 @@ namespace System.Web.UI.WebControls {
 		{
 			TrackViewState();
 		}
+		
+		internal Exception GetNotSupportedPropException (string propName)
+		{
+			return new System.NotSupportedException ("The property '" + propName + "' is not supported in " + GetType().Name); 
+		}
 
 		[MonoTODO ("Render this")]
 		[DefaultValueAttribute ("")]

+ 0 - 19
mcs/class/System.Web/System.Web.UI.WebControls/DataControlFieldCell.cs

@@ -51,25 +51,6 @@ namespace System.Web.UI.WebControls
 			get { return containerField; }
 		}
 	}
-
-	internal class AccessibleDataControlFieldCell : DataControlFieldCell
-	{
-		bool colScope;
-		
-		public AccessibleDataControlFieldCell (bool colScope, DataControlField containerField): base (HtmlTextWriterTag.Th, containerField)
-		{
-			this.colScope = colScope;
-		}
-		
-		protected override void AddAttributesToRender (HtmlTextWriter writer)
-		{
-			base.AddAttributesToRender (writer);
-			if (colScope)
-				writer.AddAttribute (HtmlTextWriterAttribute.Scope, "col");
-			else
-				writer.AddAttribute (HtmlTextWriterAttribute.Scope, "row");
-		}
-	}
 }
 	
 #endif

+ 68 - 0
mcs/class/System.Web/System.Web.UI.WebControls/DataControlFieldHeaderCell.cs

@@ -0,0 +1,68 @@
+//
+// System.Web.UI.WebControls.DataControlFieldHeaderCell.cs
+//
+// Authors:
+//  Lluis Sanchez Gual ([email protected])
+//
+// (C) 2005 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.
+//
+
+#if NET_2_0
+using System.Web.UI;
+
+namespace System.Web.UI.WebControls
+{
+	public class DataControlFieldHeaderCell : DataControlFieldCell
+	{
+		TableHeaderScope scope;
+		
+		public DataControlFieldHeaderCell (DataControlField containerField): base (HtmlTextWriterTag.Th, containerField)
+		{
+		}
+		
+		internal DataControlFieldHeaderCell (DataControlField containerField, TableHeaderScope scope): this (containerField)
+		{
+			this.scope = scope;
+		}
+		
+		public TableHeaderScope Scope {
+			get { return scope; }
+			set { scope = value; }
+		}
+		
+		protected override void AddAttributesToRender (HtmlTextWriter writer)
+		{
+			base.AddAttributesToRender (writer);
+			switch (scope) {
+				case TableHeaderScope.Column:
+					writer.AddAttribute (HtmlTextWriterAttribute.Scope, "col");
+					break;
+				case TableHeaderScope.Row:
+					writer.AddAttribute (HtmlTextWriterAttribute.Scope, "row");
+					break;
+			}
+		}
+	}
+}
+#endif

+ 16 - 15
mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs

@@ -1099,7 +1099,6 @@ namespace System.Web.UI.WebControls
 					dataSource.AllowPaging = true;
 					dataSource.PageSize = PageSize;
 					dataSource.CurrentPageIndex = PageIndex;
-					Console.WriteLine ("CPI:" + PageIndex + " " + dataSource.CurrentPageIndex);
 				}
 			}
 
@@ -1242,7 +1241,7 @@ namespace System.Web.UI.WebControls
 				DataControlField field = fields [n];
 				DataControlFieldCell cell;
 				if (((field is BoundField) && ((BoundField)field).DataField == RowHeaderColumn) || accessibleHeader)
-					cell = new AccessibleDataControlFieldCell (accessibleHeader, field);
+					cell = new DataControlFieldHeaderCell (field, accessibleHeader ? TableHeaderScope.Column : TableHeaderScope.Row);
 				else
 					cell = new DataControlFieldCell (field);
 				row.Cells.Add (cell);
@@ -1633,12 +1632,25 @@ namespace System.Web.UI.WebControls
 
 		protected override void LoadViewState (object savedState)
 		{
-			if (savedState == null)
+			if (savedState == null) {
+				base.LoadViewState (null);
 				return;
+			}
 
 			object [] states = (object []) savedState;
-			base.LoadViewState (states[0]);
 			
+			if (states[13] != null) {
+				object[] data = (object[]) states [13];
+				autoFieldProperties = new AutoGeneratedFieldProperties [data.Length];
+				for (int n=0; n<data.Length; n++) {
+					IStateManager p = new AutoGeneratedFieldProperties ();
+					p.TrackViewState ();
+					p.LoadViewState (data [n]);
+					autoFieldProperties [n] = (AutoGeneratedFieldProperties) p;
+				}
+			}
+
+			base.LoadViewState (states[0]);
 			EnsureChildControls ();
 			
 			if (states[1] != null) ((IStateManager)Columns).LoadViewState (states[1]);
@@ -1653,17 +1665,6 @@ namespace System.Web.UI.WebControls
 			if (states[10] != null) ((IStateManager)EmptyDataRowStyle).LoadViewState (states[10]);
 			if (states[11] != null) ((IStateManager)DataKeys).LoadViewState (states[11]);
 			if (states[12] != null && oldEditValues != null) ((IStateManager)oldEditValues).LoadViewState (states[12]);
-			
-			if (states[13] != null) {
-				object[] data = (object[]) states [13];
-				autoFieldProperties = new AutoGeneratedFieldProperties [data.Length];
-				for (int n=0; n<data.Length; n++) {
-					IStateManager p = new AutoGeneratedFieldProperties ();
-					p.TrackViewState ();
-					p.LoadViewState (data [n]);
-					autoFieldProperties [n] = (AutoGeneratedFieldProperties) p;
-				}
-			}
 		}
 		
 		string ICallbackEventHandler.RaiseCallbackEvent (string eventArgs)

+ 40 - 0
mcs/class/System.Web/System.Web.UI.WebControls/HiddenField.cs

@@ -0,0 +1,40 @@
+//
+// System.Web.UI.WebControls.HiddenField.cs
+//
+// Authors:
+//  Lluis Sanchez Gual ([email protected])
+//
+// (C) 2005 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.
+//
+
+#if NET_2_0
+using System.Web.UI;
+
+namespace System.Web.UI.WebControls
+{
+	public class HiddenField : Control
+	{
+	}
+}
+#endif

+ 40 - 0
mcs/class/System.Web/System.Web.UI.WebControls/ImageField.cs

@@ -0,0 +1,40 @@
+//
+// System.Web.UI.WebControls.ImageField.cs
+//
+// Authors:
+//  Lluis Sanchez Gual ([email protected])
+//
+// (C) 2005 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.
+//
+
+#if NET_2_0
+using System.Web.UI;
+
+namespace System.Web.UI.WebControls
+{
+	public class ImageField : DataControlField
+	{
+	}
+}
+#endif

+ 1 - 1
mcs/class/System.Web/System.Web.UI.WebControls/Label.cs

@@ -49,7 +49,7 @@ namespace System.Web.UI.WebControls
 	[ToolboxData("<{0}:Label runat=\"server\">Label</{0}:Label>")]
 	public class Label : WebControl
 #if NET_2_0
-		, IStaticTextControl
+		, ITextControl
 #endif
 	{
 		public Label (): base ()

+ 219 - 0
mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSource.cs

@@ -0,0 +1,219 @@
+//
+// System.Web.UI.WebControls.ObjectDataSource
+//
+// Authors:
+//  Lluis Sanchez Gual ([email protected])
+//
+// (C) 2005 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.
+//
+
+#if NET_2_0
+using System.Collections;
+using System.Collections.Specialized;
+using System.ComponentModel;
+using System.IO;
+using System.Security.Permissions;
+
+namespace System.Web.UI.WebControls
+{
+	
+	[DefaultEventAttribute ("Selecting")]
+	[DefaultPropertyAttribute ("TypeName")]
+	[DesignerAttribute ("System.Web.UI.Design.WebControls.ObjectDataSourceDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.IDesigner")]
+	[ParseChildrenAttribute (true)]
+	[PersistChildrenAttribute (false)]
+	[AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+	[AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+	public class ObjectDataSource : DataSourceControl
+	{
+		ObjectDataSourceView defaultView;
+
+		public ObjectDataSource ()
+		{
+		}
+		
+		public ObjectDataSource (string typeName, string selectMethod)
+		{
+			SelectMethod = selectMethod;
+			TypeName = typeName;
+		}
+		
+		ObjectDataSourceView DefaultView {
+			get {
+				if (defaultView == null)
+					defaultView = new ObjectDataSourceView (this, "DefaultView", Context);
+				return defaultView;
+			}
+		}
+		
+		public event ObjectDataSourceObjectEventHandler ObjectCreated {
+			add { DefaultView.ObjectCreated += value; }
+			remove { DefaultView.ObjectCreated -= value; }
+		}
+		
+		public event ObjectDataSourceObjectEventHandler ObjectCreating {
+			add { DefaultView.ObjectCreating += value; }
+			remove { DefaultView.ObjectCreating -= value; }
+		}
+		
+		public event ObjectDataSourceDisposingEventHandler ObjectDisposing {
+			add { DefaultView.ObjectDisposing += value; }
+			remove { DefaultView.ObjectDisposing -= value; }
+		}
+		
+/*		public event ObjectDataSourceResolvingMethodEventHandler ResolvingMethod {
+			add { DefaultView.ResolvingMethod += value; }
+			remove { DefaultView.ResolvingMethod -= value; }
+		}
+*/
+		public event ObjectDataSourceStatusEventHandler Selected {
+			add { DefaultView.Selected += value; }
+			remove { DefaultView.Selected -= value; }
+		}
+		
+		public event ObjectDataSourceSelectingEventHandler Selecting {
+			add { DefaultView.Selecting += value; }
+			remove { DefaultView.Selecting -= value; }
+		}
+		
+		public event ObjectDataSourceStatusEventHandler Updated {
+			add { DefaultView.Updated += value; }
+			remove { DefaultView.Updated -= value; }
+		}
+		
+		public event ObjectDataSourceMethodEventHandler Updating {
+			add { DefaultView.Updating += value; }
+			remove { DefaultView.Updating -= value; }
+		}
+
+	    [WebCategoryAttribute ("Paging")]
+	    [DefaultValueAttribute (false)]
+		public virtual bool EnablePaging {
+			get { return DefaultView.EnablePaging; }
+			set { DefaultView.EnablePaging = value; }
+		}
+		
+	    [WebCategoryAttribute ("Paging")]
+	    [DefaultValueAttribute ("maximumRows")]
+		public string MaximumRowsParameterName {
+			get { return DefaultView.MaximumRowsParameterName; }
+			set { DefaultView.MaximumRowsParameterName = value; }
+		}
+		
+	    [WebCategoryAttribute ("Paging")]
+	    [DefaultValueAttribute ("")]
+		public virtual string SelectCountMethod {
+			get { return DefaultView.SelectCountMethod; }
+			set { DefaultView.SelectCountMethod = value; }
+		}
+		
+	    [DefaultValueAttribute ("")]
+	    [WebCategoryAttribute ("Data")]
+		public virtual string SelectMethod {
+			get { return DefaultView.SelectMethod; }
+			set { DefaultView.SelectMethod = value; }
+		}
+		
+	    [WebCategoryAttribute ("Data")]
+	    [MergablePropertyAttribute (false)]
+	    [EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
+	    [DefaultValueAttribute (null)]
+	    [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
+		public ParameterCollection SelectParameters {
+			get { return DefaultView.SelectParameters; }
+		}
+
+	    [WebCategoryAttribute ("Paging")]
+	    [DefaultValueAttribute ("startRowIndex")]
+		public string StartRowIndexParameterName {
+			get { return DefaultView.StartRowIndexParameterName; }
+			set { DefaultView.StartRowIndexParameterName = value; }
+		}
+		
+	    [DefaultValueAttribute ("")]
+	    [WebCategoryAttribute ("Data")]
+		public virtual string TypeName {
+			get { return DefaultView.TypeName; }
+			set { DefaultView.TypeName = value; }
+		}
+		
+	    [DefaultValueAttribute ("")]
+	    [WebCategoryAttribute ("Data")]
+		public virtual string UpdateMethod {
+			get { return DefaultView.UpdateMethod; }
+			set { DefaultView.UpdateMethod = value; }
+		}
+		
+	    [WebCategoryAttribute ("Data")]
+	    [MergablePropertyAttribute (false)]
+	    [EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
+	    [DefaultValueAttribute (null)]
+	    [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
+		public ParameterCollection UpdateParameters {
+			get { return DefaultView.UpdateParameters; }
+		}
+		
+		protected override DataSourceView GetView (string viewName)
+		{
+			return DefaultView;
+		}
+		
+		protected override ICollection GetViewNames ()
+		{
+			return new string [] { "DefaultView" };
+		}
+		
+		public IEnumerable Select ()
+		{
+			return DefaultView.Select (DataSourceSelectArguments.Empty);
+		}
+		
+		protected override void LoadViewState (object savedState)
+		{
+			if (savedState == null) {
+				base.LoadViewState (null);
+				((IStateManager)DefaultView).LoadViewState (null);
+			} else {
+				Pair p = (Pair) savedState;
+				base.LoadViewState (p.First);
+				((IStateManager)DefaultView).LoadViewState (p.Second);
+			}
+		}
+
+		protected override object SaveViewState()
+		{
+			object baseState = base.SaveViewState ();
+			object viewState = ((IStateManager)DefaultView).SaveViewState ();
+			if (baseState != null || viewState != null) return new Pair (baseState, viewState);
+			else return null;
+		}
+
+		protected override void TrackViewState()
+		{
+			((IStateManager)DefaultView).TrackViewState ();
+		}
+	}
+}
+#endif
+

+ 1 - 1
mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSourceMethodEventArgs.cs

@@ -35,7 +35,7 @@ using System.Collections.Specialized;
 
 namespace System.Web.UI.WebControls
 {
-	public class ObjectDataSourceMethodEventArgs : EventArgs
+	public class ObjectDataSourceMethodEventArgs : System.ComponentModel.CancelEventArgs
 	{
 		private IOrderedDictionary parameters; 
 		

+ 8 - 2
mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSourceSelectingEventArgs.cs

@@ -37,16 +37,22 @@ namespace System.Web.UI.WebControls
 {
 	public class ObjectDataSourceSelectingEventArgs: ObjectDataSourceMethodEventArgs
 	{
-		private bool executeSelectCount;  
+		private bool executeSelectCount;
+		private DataSourceSelectArguments arguments;
 		
-		public ObjectDataSourceSelectingEventArgs (IOrderedDictionary inputParameters, bool executeSelectCount) : base (inputParameters)
+		public ObjectDataSourceSelectingEventArgs (IOrderedDictionary inputParameters, DataSourceSelectArguments arguments, bool executeSelectCount) : base (inputParameters)
 		{
 			this.executeSelectCount = executeSelectCount;
+			this.arguments = arguments;
 		}
 		
 		public bool ExecutingSelectCount {
 			get { return executeSelectCount; }
 		}
+		
+		public DataSourceSelectArguments Arguments {
+			get { return arguments; }
+		}
 	}
 }
 #endif

+ 580 - 0
mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSourceView.cs

@@ -0,0 +1,580 @@
+//
+// System.Web.UI.WebControls.ObjectDataSourceView
+//
+// Authors:
+//  Lluis Sanchez Gual ([email protected])
+//
+// (C) 2005 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.
+//
+
+#if NET_2_0
+using System;
+using System.Reflection;
+using System.Collections;
+using System.Collections.Specialized;
+using System.ComponentModel;
+using System.IO;
+using System.Data;
+
+namespace System.Web.UI.WebControls
+{
+
+	public class ObjectDataSourceView : DataSourceView, IStateManager
+	{
+		ObjectDataSource owner;
+		HttpContext context;
+		Type objectType;
+		
+		StateBag viewState = new StateBag ();
+		ParameterCollection selectParameters;
+		ParameterCollection updateParameters;
+		
+		private static readonly object ObjectCreatedEvent = new object();
+		private static readonly object ObjectCreatingEvent = new object();
+		private static readonly object ObjectDisposingEvent = new object();
+//		private static readonly object ResolvingMethodEvent = new object();
+		private static readonly object SelectedEvent = new object();
+		private static readonly object SelectingEvent = new object();
+		private static readonly object UpdatedEvent = new object();
+		private static readonly object UpdatingEvent = new object();
+		
+		public ObjectDataSourceView (ObjectDataSource owner, string name, HttpContext context): base (owner, name)
+		{
+			this.owner = owner;
+			this.context = context;
+		}
+		
+		public event ObjectDataSourceObjectEventHandler ObjectCreated {
+			add { Events.AddHandler (ObjectCreatedEvent, value); }
+			remove { Events.RemoveHandler (ObjectCreatedEvent, value); }
+		}
+		
+		public event ObjectDataSourceObjectEventHandler ObjectCreating {
+			add { Events.AddHandler (ObjectCreatingEvent, value); }
+			remove { Events.RemoveHandler (ObjectCreatingEvent, value); }
+		}
+		
+		public event ObjectDataSourceDisposingEventHandler ObjectDisposing {
+			add { Events.AddHandler (ObjectDisposingEvent, value); }
+			remove { Events.RemoveHandler (ObjectDisposingEvent, value); }
+		}
+		
+/*		public event ObjectDataSourceResolvingMethodEventHandler ResolvingMethod {
+			add { Events.AddHandler (ResolvingMethodEvent, value); }
+			remove { Events.RemoveHandler (ResolvingMethodEvent, value); }
+		}
+*/
+		public event ObjectDataSourceStatusEventHandler Selected {
+			add { Events.AddHandler (SelectedEvent, value); }
+			remove { Events.RemoveHandler (SelectedEvent, value); }
+		}
+		
+		public event ObjectDataSourceSelectingEventHandler Selecting {
+			add { Events.AddHandler (SelectingEvent, value); }
+			remove { Events.RemoveHandler (SelectingEvent, value); }
+		}
+		
+		public event ObjectDataSourceStatusEventHandler Updated {
+			add { Events.AddHandler (UpdatedEvent, value); }
+			remove { Events.RemoveHandler (UpdatedEvent, value); }
+		}
+		
+		public event ObjectDataSourceMethodEventHandler Updating {
+			add { Events.AddHandler (UpdatingEvent, value); }
+			remove { Events.RemoveHandler (UpdatingEvent, value); }
+		}
+		
+		protected virtual void OnObjectCreated (ObjectDataSourceEventArgs e)
+		{
+			if (Events != null) {
+				ObjectDataSourceObjectEventHandler eh = (ObjectDataSourceObjectEventHandler) Events [ObjectCreatedEvent];
+				if (eh != null) eh (this, e);
+			}
+		}
+		
+		protected virtual void OnObjectCreating (ObjectDataSourceEventArgs e)
+		{
+			if (Events != null) {
+				ObjectDataSourceObjectEventHandler eh = (ObjectDataSourceObjectEventHandler) Events [ObjectCreatingEvent];
+				if (eh != null) eh (this, e);
+			}
+		}
+		
+		protected virtual void OnObjectDisposing (ObjectDataSourceDisposingEventArgs e)
+		{
+			if (Events != null) {
+				ObjectDataSourceDisposingEventHandler eh = (ObjectDataSourceDisposingEventHandler) Events [ObjectDisposingEvent];
+				if (eh != null) eh (this, e);
+			}
+		}
+		
+/*		protected virtual void OnResolvingMethod (ObjectDataSourceResolvingMethodEventArgs e)
+		{
+			if (Events != null) {
+				ObjectDataSourceResolvingMethodEventHandler eh = (ObjectDataSourceResolvingMethodEventHandler) Events [ResolvingMethodEvent];
+				if (eh != null) eh (this, e);
+			}
+		}
+*/
+		
+		protected virtual void OnSelected (ObjectDataSourceStatusEventArgs e)
+		{
+			if (Events != null) {
+				ObjectDataSourceStatusEventHandler eh = (ObjectDataSourceStatusEventHandler) Events [SelectedEvent];
+				if (eh != null) eh (this, e);
+			}
+		}
+		
+		protected virtual void OnSelecting (ObjectDataSourceSelectingEventArgs e)
+		{
+			if (Events != null) {
+				ObjectDataSourceSelectingEventHandler eh = (ObjectDataSourceSelectingEventHandler) Events [SelectingEvent];
+				if (eh != null) eh (this, e);
+			}
+		}
+		
+		protected virtual void OnUpdated (ObjectDataSourceStatusEventArgs e)
+		{
+			if (Events != null) {
+				ObjectDataSourceStatusEventHandler eh = (ObjectDataSourceStatusEventHandler) Events [UpdatedEvent];
+				if (eh != null) eh (this, e);
+			}
+		}
+		
+		protected virtual void OnUpdating (ObjectDataSourceMethodEventArgs e)
+		{
+			if (Events != null) {
+				ObjectDataSourceMethodEventHandler eh = (ObjectDataSourceMethodEventHandler) Events [UpdatingEvent];
+				if (eh != null) eh (this, e);
+			}
+		}
+		
+		protected StateBag ViewState {
+			get { return viewState; }
+		}
+		
+		public override bool CanPage {
+			get { return EnablePaging; }
+		}
+		
+		public override bool CanRetrieveTotalRowCount {
+			get { return SelectCountMethod.Length > 0; }
+		}
+		
+		public override bool CanUpdate {
+			get { return UpdateMethod.Length > 0; }
+		}
+		
+		public virtual bool EnablePaging {
+			get {
+				object ret = ViewState ["EnablePaging"];
+				return ret != null ? (bool)ret : false;
+			}
+			set {
+				ViewState ["EnablePaging"] = value;
+			}
+		}
+		
+		public string MaximumRowsParameterName {
+			get {
+				object ret = ViewState ["MaximumRowsParameterName"];
+				return ret != null ? (string)ret : "maximumRows";
+			}
+			set {
+				ViewState ["MaximumRowsParameterName"] = value;
+			}
+		}
+		
+		public virtual string SelectCountMethod {
+			get {
+				object ret = ViewState ["SelectCountMethod"];
+				return ret != null ? (string)ret : string.Empty;
+			}
+			set {
+				ViewState ["SelectCountMethod"] = value;
+			}
+		}
+		
+		public virtual string SelectMethod {
+			get {
+				object ret = ViewState ["SelectMethod"];
+				return ret != null ? (string)ret : string.Empty;
+			}
+			set {
+				ViewState ["SelectMethod"] = value;
+			}
+		}
+		
+		public ParameterCollection SelectParameters {
+			get {
+				if (selectParameters == null) {
+					selectParameters = new ParameterCollection ();
+					if (((IStateManager)this).IsTrackingViewState)
+						((IStateManager)selectParameters).TrackViewState ();
+				}
+				return selectParameters;
+			}
+		}
+		
+		public string StartRowIndexParameterName {
+			get {
+				object ret = ViewState ["StartRowIndexParameterName"];
+				return ret != null ? (string)ret : "startRowIndex";
+			}
+			set {
+				ViewState ["StartRowIndexParameterName"] = value;
+			}
+		}
+		
+		public virtual string TypeName {
+			get {
+				object ret = ViewState ["TypeName"];
+				return ret != null ? (string)ret : string.Empty;
+			}
+			set {
+				ViewState ["TypeName"] = value;
+				objectType = null;
+			}
+		}
+		
+		public virtual string UpdateMethod {
+			get {
+				object ret = ViewState ["UpdateMethod"];
+				return ret != null ? (string)ret : string.Empty;
+			}
+			set {
+				ViewState ["UpdateMethod"] = value;
+			}
+		}
+		
+		public ParameterCollection UpdateParameters {
+			get {
+				if (updateParameters == null) {
+					updateParameters = new ParameterCollection ();
+					if (((IStateManager)this).IsTrackingViewState)
+						((IStateManager)updateParameters).TrackViewState ();
+				}
+				return updateParameters;
+			}
+		}
+		
+		Type ObjectType {
+			get {
+				if (objectType == null) {
+					objectType = Type.GetType (TypeName);
+					if (objectType == null)
+						throw new InvalidOperationException ("Type not found: " + TypeName);
+				}
+				return objectType;
+			}
+		}
+		
+		public IEnumerable Select (DataSourceSelectArguments arguments)
+		{
+			return ExecuteSelect (arguments);
+		}
+		
+		protected override int ExecuteUpdate (IDictionary keys, IDictionary values, IDictionary oldValues)
+		{
+			Hashtable allValues = new Hashtable ();
+			foreach (DictionaryEntry de in keys)
+				allValues [de.Key] = de.Value;
+			foreach (DictionaryEntry de in values)
+				allValues [de.Key] = de.Value;
+
+			IOrderedDictionary paramValues = MergeParameterValues (UpdateParameters, allValues);
+			
+			ObjectDataSourceMethodEventArgs args = new ObjectDataSourceMethodEventArgs (paramValues);
+			OnUpdating (args);
+			if (args.Cancel)
+				return -1;
+			
+			ObjectDataSourceStatusEventArgs rargs = InvokeMethod (UpdateMethod, paramValues);
+			OnUpdated (rargs);
+			
+			if (rargs.Exception != null && !rargs.ExceptionHandled)
+				throw rargs.Exception;
+
+			return -1;
+		}
+		
+		protected internal override IEnumerable ExecuteSelect (DataSourceSelectArguments arguments)
+		{
+			arguments.RaiseUnsupportedCapabilitiesError (this);
+
+			IOrderedDictionary paramValues = MergeParameterValues (SelectParameters, null);
+			
+			ObjectDataSourceSelectingEventArgs args = new ObjectDataSourceSelectingEventArgs (paramValues, arguments, false);
+			OnSelecting (args);
+			if (args.Cancel)
+				return new ArrayList ();
+			
+			if (CanRetrieveTotalRowCount && arguments.RetrieveTotalRowCount)
+				arguments.TotalRowCount = QueryTotalRowCount (paramValues, arguments);
+			
+			if (CanPage) {
+				if (StartRowIndexParameterName.Length == 0)
+					throw new InvalidOperationException ("Paging is enabled, but the StartRowIndexParameterName property is not set.");
+				if (MaximumRowsParameterName.Length == 0)
+					throw new InvalidOperationException ("Paging is enabled, but the MaximumRowsParameterName property is not set.");
+				paramValues [StartRowIndexParameterName] = arguments.StartRowIndex;
+				paramValues [MaximumRowsParameterName] = arguments.MaximumRows;
+			}
+			
+			object result = InvokeSelect (SelectMethod, paramValues);
+			
+			if (result is DataSet) {
+				DataSet dset = (DataSet) result;
+				if (dset.Tables.Count == 0)
+					throw new InvalidOperationException ("The select method returnet a DataSet which doesn't contain any table.");
+				result = dset.Tables [0];
+			}
+			
+			if (result is DataTable) {
+				DataView dview = new DataView ((DataTable)result);
+				return dview;
+			}
+			
+			if (result is IEnumerable)
+				return (IEnumerable) result;
+			else
+				return new object[] { result };
+		}
+		
+		protected virtual int QueryTotalRowCount (IOrderedDictionary mergedParameters, DataSourceSelectArguments arguments)
+		{
+			ObjectDataSourceSelectingEventArgs countArgs = new ObjectDataSourceSelectingEventArgs (mergedParameters, arguments, true);
+			OnSelecting (countArgs);
+			if (countArgs.Cancel)
+				return 0;
+			
+			object count = InvokeSelect (SelectCountMethod, mergedParameters);
+			return (int) Convert.ChangeType (count, typeof(int));
+		}
+		
+		object InvokeSelect (string methodName, IOrderedDictionary paramValues)
+		{
+			ObjectDataSourceStatusEventArgs rargs = InvokeMethod (methodName, paramValues);
+			OnSelected (rargs);
+			
+			if (rargs.Exception != null && !rargs.ExceptionHandled)
+				throw rargs.Exception;
+
+			return rargs.ReturnValue;
+		}
+		
+		ObjectDataSourceStatusEventArgs InvokeMethod (string methodName, IOrderedDictionary paramValues)
+		{
+			object instance = null;
+			MethodInfo method = GetObjectMethod (methodName, paramValues);
+			if (!method.IsStatic)
+				instance = CreateObjectInstance ();
+
+			ParameterInfo[] pars = method.GetParameters ();
+			
+			ArrayList outParamInfos;
+			object[] methodArgs = GetParameterArray (pars, paramValues, out outParamInfos); 
+			
+			if (methodArgs == null)
+				throw CreateMethodException (methodName, paramValues);
+					
+			object result = null;
+			Hashtable outParams = null;
+			
+			try {
+				result = method.Invoke (instance, methodArgs);
+				if (outParamInfos != null) {
+					outParams = new Hashtable ();
+					foreach (ParameterInfo op in outParamInfos)
+						outParams [op.Name] = methodArgs [op.Position - 1];
+				}
+				return new ObjectDataSourceStatusEventArgs (result, outParams, null);
+			}
+			catch (Exception ex) {
+				return new ObjectDataSourceStatusEventArgs (result, outParams, ex);
+			}
+			finally {
+				if (instance != null)
+					DisposeObjectInstance (instance);
+			}
+		}
+		
+		MethodInfo GetObjectMethod (string methodName, IOrderedDictionary parameters)
+		{
+			MemberInfo[] methods = ObjectType.GetMember (methodName);
+			if (methods.Length > 1) {
+				// MSDN: The ObjectDataSource resolves method overloads by method name and number
+				// of parameters; the names and types of the parameters are not considered.
+				foreach (MemberInfo mi in methods) {
+					MethodInfo me = mi as MethodInfo;
+					if (me != null && me.GetParameters().Length == parameters.Count)
+						return me;
+				}
+			}
+			else if (methods.Length == 1) {
+				MethodInfo me = methods[0] as MethodInfo;
+				if (me != null && me.GetParameters().Length == parameters.Count)
+					return me;
+			}
+			
+			throw CreateMethodException (methodName, parameters);
+		}
+		
+		Exception CreateMethodException (string methodName, IOrderedDictionary parameters)
+		{
+			string s = "";
+			foreach (string p in parameters.Keys) {
+				s += p + ", ";
+			}
+			return new InvalidOperationException ("ObjectDataSource " + owner.ID + " could not find a method named '" + methodName + "' with parameters " + s + "in type '" + ObjectType + "'.");
+		}
+		
+		object CreateObjectInstance ()
+		{
+			ObjectDataSourceEventArgs args = new ObjectDataSourceEventArgs (null);
+			OnObjectCreating (args);
+			
+			if (args.ObjectInstance != null)
+				return args.ObjectInstance;
+				
+			object ob = Activator.CreateInstance (ObjectType);
+			
+			args.ObjectInstance = ob;
+			OnObjectCreated (args);
+			
+			return args.ObjectInstance;
+		}
+		
+		void DisposeObjectInstance (object obj)
+		{
+			ObjectDataSourceDisposingEventArgs args = new ObjectDataSourceDisposingEventArgs (obj);
+			OnObjectDisposing (args);
+			
+			if (!args.Cancel) {
+				IDisposable disp = obj as IDisposable;
+				if (disp != null) disp.Dispose ();
+			}
+		}
+		
+		IOrderedDictionary MergeParameterValues (ParameterCollection viewParams, IDictionary values)
+		{
+			OrderedDictionary mergedValues = new OrderedDictionary ();
+			foreach (Parameter p in viewParams) {
+				object val = values != null ? values [p.Name] : null;
+				if (val != null)
+					val = Convert.ChangeType (val, p.Type);
+				else
+					val = p.GetValue (context, owner);
+				
+				mergedValues [p.Name] = val;
+			}
+			
+			if (values != null) {
+				foreach (DictionaryEntry de in values)
+					if (!mergedValues.Contains (de.Key))
+						mergedValues [de.Key] = de.Value;
+			}
+			
+			return mergedValues;
+		}
+		
+		object[] GetParameterArray (ParameterInfo[] methodParams, IOrderedDictionary viewParams, out ArrayList outParamInfos)
+		{
+			// FIXME: make this case insensitive
+
+			outParamInfos = null;
+			object[] values = new object [methodParams.Length];
+			foreach (ParameterInfo mp in methodParams) {
+			
+				// Parameter names must match
+				if (!viewParams.Contains (mp.Name)) return null;
+					
+				values [mp.Position] = ConvertParameter (mp.ParameterType, viewParams [mp.Name]);
+				if (mp.ParameterType.IsByRef) {
+					if (outParamInfos == null) outParamInfos = new ArrayList ();
+					outParamInfos.Add (mp);
+				}
+			}
+			return values;
+		}
+		
+		object ConvertParameter (Type targetType, object value)
+		{
+			return Convert.ChangeType (value, targetType);
+		}
+		
+		protected virtual void LoadViewState (object savedState)
+		{
+			object[] state = (savedState == null) ? new object [3] : (object[]) savedState;
+			viewState.LoadViewState (state[0]);
+			((IStateManager)SelectParameters).LoadViewState (state[1]); 
+			((IStateManager)UpdateParameters).LoadViewState (state[1]); 
+		}
+
+		protected virtual object SaveViewState()
+		{
+			object[] state = new object [3];
+			state [0] = viewState.SaveViewState ();
+			
+			if (selectParameters != null)
+				state [1] = ((IStateManager)selectParameters).SaveViewState ();
+			if (updateParameters != null)
+				state [2] = ((IStateManager)updateParameters).SaveViewState ();
+			
+			foreach (object ob in state)
+				if (ob != null) return state;
+			
+			return null;
+		}
+		
+		protected virtual void TrackViewState()
+		{
+			viewState.TrackViewState ();
+			if (selectParameters != null) ((IStateManager)selectParameters).TrackViewState ();
+			if (updateParameters != null) ((IStateManager)updateParameters).TrackViewState ();
+		}
+		
+		bool IStateManager.IsTrackingViewState
+		{
+			get { return viewState.IsTrackingViewState; }
+		}
+		
+		void IStateManager.TrackViewState()
+		{
+			TrackViewState ();
+		}
+		
+		void IStateManager.LoadViewState (object savedState)
+		{
+			LoadViewState (savedState);
+		}
+
+		object IStateManager.SaveViewState()
+		{
+			return SaveViewState ();
+		}
+	}
+}
+#endif
+

+ 5 - 0
mcs/class/System.Web/System.Web.UI.WebControls/Parameter.cs

@@ -251,6 +251,11 @@ namespace System.Web.UI.WebControls {
 		{
 			return this.DefaultValue;
 		}
+		
+		internal object GetValue (HttpContext context, Control control)
+		{
+			return Evaluate (context, control);
+		}
 
 		protected internal virtual void SetDirty()
 		{

+ 40 - 0
mcs/class/System.Web/System.Web.UI.WebControls/TemplateField.cs

@@ -0,0 +1,40 @@
+//
+// System.Web.UI.WebControls.TemplateField.cs
+//
+// Authors:
+//  Lluis Sanchez Gual ([email protected])
+//
+// (C) 2005 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.
+//
+
+#if NET_2_0
+using System.Web.UI;
+
+namespace System.Web.UI.WebControls
+{
+	public class TemplateField : DataControlField
+	{
+	}
+}
+#endif