Prechádzať zdrojové kódy

2006-12-28 Igor Zelmanovich <[email protected]>

	* DetailsView.cs:
	* GridView.cs:
	* FormView.cs:
	control's behavior depends on using DataSource or DataSourceID 
	property for binding	


svn path=/trunk/mcs/; revision=70165
Igor Zelmanovich 19 rokov pred
rodič
commit
499d009db5

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

@@ -1,3 +1,11 @@
+2006-12-28 Igor Zelmanovich <[email protected]>
+
+	* DetailsView.cs:
+	* GridView.cs:
+	* FormView.cs:
+	control's behavior depends on using DataSource or DataSourceID 
+	property for binding	
+
 2006-12-27 Igor Zelmanovich <[email protected]>
 
 	* CommandField.cs: fixed: 

+ 104 - 59
mcs/class/System.Web/System.Web.UI.WebControls/DetailsView.cs

@@ -69,6 +69,7 @@ namespace System.Web.UI.WebControls
 		
 		PropertyDescriptor[] cachedKeyProperties;
 		readonly string[] emptyKeys = new string[0];
+		readonly string unhandledEventExceptionMessage = "The DetailsView '{0}' fired event {1} which wasn't handled.";
 		
 		// View state
 		DataControlFieldCollection columns;
@@ -186,8 +187,13 @@ namespace System.Web.UI.WebControls
 		{
 			if (Events != null) {
 				DetailsViewPageEventHandler eh = (DetailsViewPageEventHandler) Events [PageIndexChangingEvent];
-				if (eh != null) eh (this, e);
+				if (eh != null) {
+					eh (this, e);
+					return;
+				}
 			}
+			if (!IsBoundUsingDataSourceID)
+				throw new HttpException (String.Format (unhandledEventExceptionMessage, ID, "PageIndexChanging"));
 		}
 		
 		protected virtual void OnItemCommand (DetailsViewCommandEventArgs e)
@@ -226,16 +232,26 @@ namespace System.Web.UI.WebControls
 		{
 			if (Events != null) {
 				DetailsViewInsertEventHandler eh = (DetailsViewInsertEventHandler) Events [ItemInsertingEvent];
-				if (eh != null) eh (this, e);
+				if (eh != null) {
+					eh (this, e);
+					return;
+				}
 			}
+			if (!IsBoundUsingDataSourceID)
+				throw new HttpException (String.Format (unhandledEventExceptionMessage, ID, "ItemInserting"));
 		}
 		
 		protected virtual void OnItemDeleting (DetailsViewDeleteEventArgs e)
 		{
 			if (Events != null) {
 				DetailsViewDeleteEventHandler eh = (DetailsViewDeleteEventHandler) Events [ItemDeletingEvent];
-				if (eh != null) eh (this, e);
+				if (eh != null) {
+					eh (this, e);
+					return;
+				}
 			}
+			if (!IsBoundUsingDataSourceID)
+				throw new HttpException (String.Format (unhandledEventExceptionMessage, ID, "ItemDeleting"));
 		}
 		
 		protected virtual void OnModeChanged (EventArgs e)
@@ -250,8 +266,13 @@ namespace System.Web.UI.WebControls
 		{
 			if (Events != null) {
 				DetailsViewModeEventHandler eh = (DetailsViewModeEventHandler) Events [ModeChangingEvent];
-				if (eh != null) eh (this, e);
+				if (eh != null) {
+					eh (this, e);
+					return;
+				}
 			}
+			if (!IsBoundUsingDataSourceID)
+				throw new HttpException (String.Format (unhandledEventExceptionMessage, ID, "ModeChanging"));
 		}
 		
 		protected virtual void OnItemUpdated (DetailsViewUpdatedEventArgs e)
@@ -266,8 +287,13 @@ namespace System.Web.UI.WebControls
 		{
 			if (Events != null) {
 				DetailsViewUpdateEventHandler eh = (DetailsViewUpdateEventHandler) Events [ItemUpdatingEvent];
-				if (eh != null) eh (this, e);
+				if (eh != null) {
+					eh (this, e);
+					return;
+				}
 			}
+			if (!IsBoundUsingDataSourceID)
+				throw new HttpException (String.Format (unhandledEventExceptionMessage, ID, "ItemUpdating"));
 		}
 		
 		
@@ -1309,17 +1335,25 @@ namespace System.Web.UI.WebControls
 						row.ControlStyle.CopyFrom (rowStyle);
 					if ((row.RowState & DataControlRowState.Alternate) != 0 && alternatingRowStyle != null && !alternatingRowStyle.IsEmpty)
 						row.ControlStyle.CopyFrom (alternatingRowStyle);
-					if ((row.RowState & DataControlRowState.Edit) != 0 && editRowStyle != null && !editRowStyle.IsEmpty)
-						row.ControlStyle.CopyFrom (editRowStyle);
-					if ((row.RowState & DataControlRowState.Insert) != 0 && insertRowStyle != null && !insertRowStyle.IsEmpty)
-						row.ControlStyle.CopyFrom (insertRowStyle);
 					break;
 				default:
 					break;
 				}
 
-				if ((row.ContainingField is CommandField) && commandRowStyle != null && !commandRowStyle.IsEmpty)
-					row.ControlStyle.CopyFrom (commandRowStyle);
+				if (row.ContainingField is CommandField) {
+					if (commandRowStyle != null && !commandRowStyle.IsEmpty)
+						row.ControlStyle.CopyFrom (commandRowStyle);
+				}
+				else {
+					if ((row.RowState & DataControlRowState.Edit) != 0 && editRowStyle != null && !editRowStyle.IsEmpty)
+						row.ControlStyle.CopyFrom (editRowStyle);
+					if ((row.RowState & DataControlRowState.Insert) != 0) {
+						if (insertRowStyle != null && !insertRowStyle.IsEmpty)
+							row.ControlStyle.CopyFrom (insertRowStyle);
+						else if (editRowStyle != null && !editRowStyle.IsEmpty)
+							row.ControlStyle.CopyFrom (editRowStyle);
+					}
+				}
 
 				for (int n = 0; n < row.Cells.Count; n++) {
 					DataControlFieldCell fcell = row.Cells [n] as DataControlFieldCell;
@@ -1436,11 +1470,11 @@ namespace System.Web.UI.WebControls
 				break;
 					
 			case DataControlCommands.EditCommandName:
-				ChangeMode (DetailsViewMode.Edit);
+				ProcessChangeMode (DetailsViewMode.Edit);
 				break;
 					
 			case DataControlCommands.NewCommandName:
-				ChangeMode (DetailsViewMode.Insert);
+				ProcessChangeMode (DetailsViewMode.Insert);
 				break;
 					
 			case DataControlCommands.UpdateCommandName:
@@ -1465,33 +1499,45 @@ namespace System.Web.UI.WebControls
 		{
 			DetailsViewPageEventArgs args = new DetailsViewPageEventArgs (newIndex);
 			OnPageIndexChanging (args);
-			if (!args.Cancel) {
-				if (args.NewPageIndex < 0 || args.NewPageIndex >= PageCount)
-					return;
-				EndRowEdit (false);
-				PageIndex = args.NewPageIndex;
-				OnPageIndexChanged (EventArgs.Empty);
-			}
+
+			if (args.Cancel || !IsBoundUsingDataSourceID)
+				return;
+			
+			if (args.NewPageIndex < 0 || args.NewPageIndex >= PageCount)
+				return;
+			EndRowEdit (false);
+			PageIndex = args.NewPageIndex;
+			OnPageIndexChanged (EventArgs.Empty);
 		}
 		
 		public void ChangeMode (DetailsViewMode newMode)
+		{
+			CurrentMode = newMode;
+			RequireBinding ();
+		}
+
+		void ProcessChangeMode (DetailsViewMode newMode)
 		{
 			DetailsViewModeEventArgs args = new DetailsViewModeEventArgs (newMode, false);
 			OnModeChanging (args);
-			if (!args.Cancel) {
-				CurrentMode = args.NewMode;
-				OnModeChanged (EventArgs.Empty);
-				RequireBinding ();
-			}
+
+			if (args.Cancel || !IsBoundUsingDataSourceID)
+				return;
+
+			ChangeMode (args.NewMode);
+
+			OnModeChanged (EventArgs.Empty);
 		}
-		
+
 		void CancelEdit ()
 		{
 			DetailsViewModeEventArgs args = new DetailsViewModeEventArgs (DetailsViewMode.ReadOnly, true);
 			OnModeChanging (args);
-			if (!args.Cancel) {
-				EndRowEdit ();
-			}
+
+			if (args.Cancel || !IsBoundUsingDataSourceID)
+				return;
+
+			EndRowEdit ();
 		}
 
 		public virtual void UpdateItem (bool causesValidation)
@@ -1513,15 +1559,14 @@ namespace System.Web.UI.WebControls
 			
 			DetailsViewUpdateEventArgs args = new DetailsViewUpdateEventArgs (param, currentEditRowKeys, currentEditOldValues, currentEditNewValues);
 			OnItemUpdating (args);
-			if (!args.Cancel) {
-				DataSourceView view = GetData ();
-				if (view == null)
-					throw new HttpException ("The DataSourceView associated to data bound control was null");
-				if (view.CanUpdate)
-					view.Update (currentEditRowKeys, currentEditNewValues, currentEditOldValues, new DataSourceViewOperationCallback (UpdateCallback));
-			}
-			else
-				EndRowEdit ();
+
+			if (args.Cancel || !IsBoundUsingDataSourceID)
+				return;
+			
+			DataSourceView view = GetData ();
+			if (view == null)
+				throw new HttpException ("The DataSourceView associated to data bound control was null");
+			view.Update (currentEditRowKeys, currentEditNewValues, currentEditOldValues, new DataSourceViewOperationCallback (UpdateCallback));
 		}
 
 		bool UpdateCallback (int recordsAffected, Exception exception)
@@ -1550,15 +1595,14 @@ namespace System.Web.UI.WebControls
 			currentEditNewValues = GetRowValues (false, true);
 			DetailsViewInsertEventArgs args = new DetailsViewInsertEventArgs (param, currentEditNewValues);
 			OnItemInserting (args);
-			if (!args.Cancel) {
-				DataSourceView view = GetData ();
-				if (view == null)
-					throw new HttpException ("The DataSourceView associated to data bound control was null");
-				if (view.CanInsert)
-					view.Insert (currentEditNewValues, new DataSourceViewOperationCallback (InsertCallback));
-			}
-			else
-				EndRowEdit ();
+
+			if (args.Cancel || !IsBoundUsingDataSourceID)
+				return;
+
+			DataSourceView view = GetData ();
+			if (view == null)
+				throw new HttpException ("The DataSourceView associated to data bound control was null");
+			view.Insert (currentEditNewValues, new DataSourceViewOperationCallback (InsertCallback));
 		}
 		
 		bool InsertCallback (int recordsAffected, Exception exception)
@@ -1580,18 +1624,19 @@ namespace System.Web.UI.WebControls
 			DetailsViewDeleteEventArgs args = new DetailsViewDeleteEventArgs (PageIndex, currentEditRowKeys, currentEditNewValues);
 			OnItemDeleting (args);
 
-			if (!args.Cancel) {
-				if (PageIndex == PageCount - 1)
-					PageIndex --;
-				RequireBinding ();
-				DataSourceView view = GetData ();
-				if (view != null && view.CanDelete)
-					view.Delete (currentEditRowKeys, currentEditNewValues, new DataSourceViewOperationCallback (DeleteCallback));
-				else {
-					DetailsViewDeletedEventArgs dargs = new DetailsViewDeletedEventArgs (0, null, currentEditRowKeys, currentEditNewValues);
-					OnItemDeleted (dargs);
-				}
-			}
+			if (args.Cancel || !IsBoundUsingDataSourceID)
+				return;
+
+			DataSourceView view = GetData ();
+			if (view != null)
+				view.Delete (currentEditRowKeys, currentEditNewValues, new DataSourceViewOperationCallback (DeleteCallback));
+			else {
+				DetailsViewDeletedEventArgs dargs = new DetailsViewDeletedEventArgs (0, null, currentEditRowKeys, currentEditNewValues);
+				OnItemDeleted (dargs);
+			}
+			if (PageIndex == PageCount - 1)
+				PageIndex --;
+			RequireBinding ();
 		}
 
 		bool DeleteCallback (int recordsAffected, Exception exception)

+ 92 - 55
mcs/class/System.Web/System.Web.UI.WebControls/FormView.cs

@@ -71,6 +71,7 @@ namespace System.Web.UI.WebControls
 		
 		PropertyDescriptor[] cachedKeyProperties;
 		readonly string[] emptyKeys = new string[0];
+		readonly string unhandledEventExceptionMessage = "The FormView '{0}' fired event {1} which wasn't handled.";
 		
 		// View state
 		PagerSettings pagerSettings;
@@ -178,8 +179,13 @@ namespace System.Web.UI.WebControls
 		{
 			if (Events != null) {
 				FormViewPageEventHandler eh = (FormViewPageEventHandler) Events [PageIndexChangingEvent];
-				if (eh != null) eh (this, e);
+				if (eh != null) {
+					eh (this, e);
+					return;
+				}
 			}
+			if (!IsBoundUsingDataSourceID)
+				throw new HttpException (String.Format (unhandledEventExceptionMessage, ID, "PageIndexChanging"));
 		}
 		
 		protected virtual void OnItemCommand (FormViewCommandEventArgs e)
@@ -218,16 +224,26 @@ namespace System.Web.UI.WebControls
 		{
 			if (Events != null) {
 				FormViewInsertEventHandler eh = (FormViewInsertEventHandler) Events [ItemInsertingEvent];
-				if (eh != null) eh (this, e);
+				if (eh != null) {
+					eh (this, e);
+					return;
+				}
 			}
+			if (!IsBoundUsingDataSourceID)
+				throw new HttpException (String.Format (unhandledEventExceptionMessage, ID, "ItemInserting"));
 		}
 		
 		protected virtual void OnItemDeleting (FormViewDeleteEventArgs e)
 		{
 			if (Events != null) {
 				FormViewDeleteEventHandler eh = (FormViewDeleteEventHandler) Events [ItemDeletingEvent];
-				if (eh != null) eh (this, e);
+				if (eh != null) {
+					eh (this, e);
+					return;
+				}
 			}
+			if (!IsBoundUsingDataSourceID)
+				throw new HttpException (String.Format (unhandledEventExceptionMessage, ID, "ItemDeleting"));
 		}
 		
 		protected virtual void OnModeChanged (EventArgs e)
@@ -242,8 +258,13 @@ namespace System.Web.UI.WebControls
 		{
 			if (Events != null) {
 				FormViewModeEventHandler eh = (FormViewModeEventHandler) Events [ModeChangingEvent];
-				if (eh != null) eh (this, e);
+				if (eh != null) {
+					eh (this, e);
+					return;
+				}
 			}
+			if (!IsBoundUsingDataSourceID)
+				throw new HttpException (String.Format (unhandledEventExceptionMessage, ID, "ModeChanging"));
 		}
 		
 		protected virtual void OnItemUpdated (FormViewUpdatedEventArgs e)
@@ -258,8 +279,13 @@ namespace System.Web.UI.WebControls
 		{
 			if (Events != null) {
 				FormViewUpdateEventHandler eh = (FormViewUpdateEventHandler) Events [ItemUpdatingEvent];
-				if (eh != null) eh (this, e);
+				if (eh != null) {
+					eh (this, e);
+					return;
+				}
 			}
+			if (!IsBoundUsingDataSourceID)
+				throw new HttpException (String.Format (unhandledEventExceptionMessage, ID, "ItemUpdating"));
 		}
 		
 		
@@ -1199,11 +1225,11 @@ namespace System.Web.UI.WebControls
 				break;
 					
 			case DataControlCommands.EditCommandName:
-				ChangeMode (FormViewMode.Edit);
+				ProcessChangeMode (FormViewMode.Edit);
 				break;
 					
 			case DataControlCommands.NewCommandName:
-				ChangeMode (FormViewMode.Insert);
+				ProcessChangeMode (FormViewMode.Insert);
 				break;
 					
 			case DataControlCommands.UpdateCommandName:
@@ -1228,34 +1254,46 @@ namespace System.Web.UI.WebControls
 		{
 			FormViewPageEventArgs args = new FormViewPageEventArgs (index);
 			OnPageIndexChanging (args);
-			if (!args.Cancel) {
-				int newIndex = args.NewPageIndex;
-				if (newIndex < 0 || newIndex >= PageCount)
-					return;
-				EndRowEdit (false);
-				PageIndex = newIndex;
-				OnPageIndexChanged (EventArgs.Empty);
-			}
+
+			if (args.Cancel || !IsBoundUsingDataSourceID)
+				return;
+
+			int newIndex = args.NewPageIndex;
+			if (newIndex < 0 || newIndex >= PageCount)
+				return;
+			EndRowEdit (false);
+			PageIndex = newIndex;
+			OnPageIndexChanged (EventArgs.Empty);
 		}
 		
 		public void ChangeMode (FormViewMode newMode)
+		{
+			CurrentMode = newMode;
+			RequireBinding ();
+		}
+
+		void ProcessChangeMode (FormViewMode newMode)
 		{
 			FormViewModeEventArgs args = new FormViewModeEventArgs (newMode, false);
 			OnModeChanging (args);
-			if (!args.Cancel) {
-				CurrentMode = args.NewMode;
-				OnModeChanged (EventArgs.Empty);
-				RequireBinding ();
-			}
+
+			if (args.Cancel || !IsBoundUsingDataSourceID)
+				return;
+
+			ChangeMode (args.NewMode);
+
+			OnModeChanged (EventArgs.Empty);
 		}
 		
 		void CancelEdit ()
 		{
 			FormViewModeEventArgs args = new FormViewModeEventArgs (FormViewMode.ReadOnly, true);
 			OnModeChanging (args);
-			if (!args.Cancel) {
-				EndRowEdit ();
-			}
+
+			if (args.Cancel || !IsBoundUsingDataSourceID)
+				return;
+
+			EndRowEdit ();
 		}
 
 		public virtual void UpdateItem (bool causesValidation)
@@ -1276,15 +1314,14 @@ namespace System.Web.UI.WebControls
 			
 			FormViewUpdateEventArgs args = new FormViewUpdateEventArgs (param, currentEditRowKeys, currentEditOldValues, currentEditNewValues);
 			OnItemUpdating (args);
-			if (!args.Cancel) {
-				DataSourceView view = GetData ();
-				if (view == null)
-					throw new HttpException ("The DataSourceView associated to data bound control was null");
-				if (view.CanUpdate)
-					view.Update (currentEditRowKeys, currentEditNewValues, currentEditOldValues, new DataSourceViewOperationCallback (UpdateCallback));
-			}
-			else
-				EndRowEdit ();
+
+			if (args.Cancel || !IsBoundUsingDataSourceID)
+				return;
+			
+			DataSourceView view = GetData ();
+			if (view == null)
+				throw new HttpException ("The DataSourceView associated to data bound control was null");
+			view.Update (currentEditRowKeys, currentEditNewValues, currentEditOldValues, new DataSourceViewOperationCallback (UpdateCallback));
 		}
 
 		bool UpdateCallback (int recordsAffected, Exception exception)
@@ -1313,15 +1350,14 @@ namespace System.Web.UI.WebControls
 			currentEditNewValues = GetRowValues (true);
 			FormViewInsertEventArgs args = new FormViewInsertEventArgs (param, currentEditNewValues);
 			OnItemInserting (args);
-			if (!args.Cancel) {
-				DataSourceView view = GetData ();
-				if (view == null)
-					throw new HttpException ("The DataSourceView associated to data bound control was null");
-				if (view.CanInsert)
-					view.Insert (currentEditNewValues, new DataSourceViewOperationCallback (InsertCallback));
-			}
-			else
-				EndRowEdit ();
+
+			if (args.Cancel || !IsBoundUsingDataSourceID)
+				return;
+
+			DataSourceView view = GetData ();
+			if (view == null)
+				throw new HttpException ("The DataSourceView associated to data bound control was null");
+			view.Insert (currentEditNewValues, new DataSourceViewOperationCallback (InsertCallback));
 		}
 		
 		bool InsertCallback (int recordsAffected, Exception exception)
@@ -1343,21 +1379,22 @@ namespace System.Web.UI.WebControls
 			FormViewDeleteEventArgs args = new FormViewDeleteEventArgs (PageIndex, currentEditRowKeys, currentEditNewValues);
 			OnItemDeleting (args);
 
-			if (!args.Cancel) {
-				if (PageIndex > 0 && PageIndex == PageCount - 1)
-					PageIndex--;
-					
-				RequireBinding ();
-					
-				DataSourceView view = GetData ();
-				if (view != null && view.CanDelete)
-					view.Delete (currentEditRowKeys, currentEditNewValues, new DataSourceViewOperationCallback (DeleteCallback));
-				else {
-					FormViewDeletedEventArgs dargs = new FormViewDeletedEventArgs (0, null, currentEditRowKeys, currentEditNewValues);
-					OnItemDeleted (dargs);
-				}
+			if (args.Cancel || !IsBoundUsingDataSourceID)
+				return;
+
+			if (PageIndex > 0 && PageIndex == PageCount - 1)
+				PageIndex--;
+				
+			RequireBinding ();
+				
+			DataSourceView view = GetData ();
+			if (view != null)
+				view.Delete (currentEditRowKeys, currentEditNewValues, new DataSourceViewOperationCallback (DeleteCallback));
+			else {
+				FormViewDeletedEventArgs dargs = new FormViewDeletedEventArgs (0, null, currentEditRowKeys, currentEditNewValues);
+				OnItemDeleted (dargs);
 			}
-		}
+		}	
 
 		bool DeleteCallback (int recordsAffected, Exception exception)
 		{

+ 71 - 34
mcs/class/System.Web/System.Web.UI.WebControls/GridView.cs

@@ -195,16 +195,26 @@ namespace System.Web.UI.WebControls
 		{
 			if (Events != null) {
 				GridViewPageEventHandler eh = (GridViewPageEventHandler) Events [PageIndexChangingEvent];
-				if (eh != null) eh (this, e);
+				if (eh != null) {
+					eh (this, e);
+					return;
+				}
 			}
+			if (!IsBoundUsingDataSourceID)
+				throw new HttpException (String.Format ("The GridView '{0}' fired event PageIndexChanging which wasn't handled.", ID));
 		}
 		
 		protected virtual void OnRowCancelingEdit (GridViewCancelEditEventArgs e)
 		{
 			if (Events != null) {
 				GridViewCancelEditEventHandler eh = (GridViewCancelEditEventHandler) Events [RowCancelingEditEvent];
-				if (eh != null) eh (this, e);
+				if (eh != null) {
+					eh (this, e);
+					return;
+				}
 			}
+			if (!IsBoundUsingDataSourceID)
+				throw new HttpException (String.Format ("The GridView '{0}' fired event RowCancelingEdit which wasn't handled.", ID));
 		}
 		
 		protected virtual void OnRowCommand (GridViewCommandEventArgs e)
@@ -243,16 +253,26 @@ namespace System.Web.UI.WebControls
 		{
 			if (Events != null) {
 				GridViewDeleteEventHandler eh = (GridViewDeleteEventHandler) Events [RowDeletingEvent];
-				if (eh != null) eh (this, e);
+				if (eh != null) {
+					eh (this, e);
+					return;
+				}
 			}
+			if (!IsBoundUsingDataSourceID)
+				throw new HttpException (String.Format ("The GridView '{0}' fired event RowDeleting which wasn't handled.", ID));
 		}
 		
 		protected virtual void OnRowEditing (GridViewEditEventArgs e)
 		{
 			if (Events != null) {
 				GridViewEditEventHandler eh = (GridViewEditEventHandler) Events [RowEditingEvent];
-				if (eh != null) eh (this, e);
+				if (eh != null) {
+					eh (this, e);
+					return;
+				}
 			}
+			if (!IsBoundUsingDataSourceID)
+				throw new HttpException (String.Format ("The GridView '{0}' fired event RowEditing which wasn't handled.", ID));
 		}
 		
 		protected virtual void OnRowUpdated (GridViewUpdatedEventArgs e)
@@ -267,8 +287,13 @@ namespace System.Web.UI.WebControls
 		{
 			if (Events != null) {
 				GridViewUpdateEventHandler eh = (GridViewUpdateEventHandler) Events [RowUpdatingEvent];
-				if (eh != null) eh (this, e);
+				if (eh != null) {
+					eh (this, e);
+					return;
+				}
 			}
+			if (!IsBoundUsingDataSourceID)
+				throw new HttpException (String.Format ("The GridView '{0}' fired event RowUpdating which wasn't handled.", ID));
 		}
 		
 		protected virtual void OnSelectedIndexChanged (EventArgs e)
@@ -299,8 +324,13 @@ namespace System.Web.UI.WebControls
 		{
 			if (Events != null) {
 				GridViewSortEventHandler eh = (GridViewSortEventHandler) Events [SortingEvent];
-				if (eh != null) eh (this, e);
+				if (eh != null) {
+					eh (this, e);
+					return;
+				}
 			}
+			if (!IsBoundUsingDataSourceID)
+				throw new HttpException (String.Format ("The GridView '{0}' fired event Sorting which wasn't handled.", ID));
 		}
 		
 		
@@ -1669,29 +1699,35 @@ namespace System.Web.UI.WebControls
 		{
 			GridViewPageEventArgs args = new GridViewPageEventArgs (newIndex);
 			OnPageIndexChanging (args);
-			if (!args.Cancel) {
-				EndRowEdit ();
-				PageIndex = args.NewPageIndex;
-				OnPageIndexChanged (EventArgs.Empty);
-			}
+			
+			if (args.Cancel || !IsBoundUsingDataSourceID)
+				return;
+			
+			EndRowEdit ();
+			PageIndex = args.NewPageIndex;
+			OnPageIndexChanged (EventArgs.Empty);
 		}
 		
 		void EditRow (int index)
 		{
 			GridViewEditEventArgs args = new GridViewEditEventArgs (index);
 			OnRowEditing (args);
-			if (!args.Cancel) {
-				EditIndex = args.NewEditIndex;
-			}
+			
+			if (args.Cancel || !IsBoundUsingDataSourceID)
+				return;
+			
+			EditIndex = args.NewEditIndex;
 		}
 		
 		void CancelEdit ()
 		{
 			GridViewCancelEditEventArgs args = new GridViewCancelEditEventArgs (EditIndex);
 			OnRowCancelingEdit (args);
-			if (!args.Cancel) {
-				EndRowEdit ();
-			}
+			
+			if (args.Cancel || !IsBoundUsingDataSourceID)
+				return;
+
+			EndRowEdit ();
 		}
 
 		[MonoTODO ("Support two-way binding expressions")]
@@ -1715,14 +1751,14 @@ namespace System.Web.UI.WebControls
 			
 			GridViewUpdateEventArgs args = new GridViewUpdateEventArgs (rowIndex, currentEditRowKeys, currentEditOldValues, currentEditNewValues);
 			OnRowUpdating (args);
-			if (!args.Cancel) {
-				DataSourceView view = GetData ();
-				if (view == null)
-					throw new HttpException ("The DataSourceView associated to data bound control was null");
-				if(view.CanUpdate)
-					view.Update (currentEditRowKeys, currentEditNewValues, currentEditOldValues, new DataSourceViewOperationCallback (UpdateCallback));
-			} else
-				EndRowEdit ();
+			
+			if (args.Cancel || !IsBoundUsingDataSourceID)
+				return;
+			
+			DataSourceView view = GetData ();
+			if (view == null)
+				throw new HttpException ("The DataSourceView associated to data bound control was null");
+			view.Update (currentEditRowKeys, currentEditNewValues, currentEditOldValues, new DataSourceViewOperationCallback (UpdateCallback));
 		}
 
 		bool UpdateCallback (int recordsAffected, Exception exception)
@@ -1745,15 +1781,16 @@ namespace System.Web.UI.WebControls
 			GridViewDeleteEventArgs args = new GridViewDeleteEventArgs (rowIndex, currentEditRowKeys, currentEditNewValues);
 			OnRowDeleting (args);
 
-			if (!args.Cancel) {
-				RequireBinding ();
-				DataSourceView view = GetData ();
-				if (view != null && view.CanDelete)
-					view.Delete (currentEditRowKeys, currentEditNewValues, new DataSourceViewOperationCallback (DeleteCallback));
-				else {
-					GridViewDeletedEventArgs dargs = new GridViewDeletedEventArgs (0, null, currentEditRowKeys, currentEditNewValues);
-					OnRowDeleted (dargs);
-				}
+			if (args.Cancel || !IsBoundUsingDataSourceID)
+				return;
+			
+			RequireBinding ();
+			DataSourceView view = GetData ();
+			if (view != null)
+				view.Delete (currentEditRowKeys, currentEditNewValues, new DataSourceViewOperationCallback (DeleteCallback));
+			else {
+				GridViewDeletedEventArgs dargs = new GridViewDeletedEventArgs (0, null, currentEditRowKeys, currentEditNewValues);
+				OnRowDeleted (dargs);
 			}
 		}
 

+ 0 - 2
mcs/class/System.Web/Test/System.Web.UI.WebControls/DetailsViewTest.cs

@@ -1206,7 +1206,6 @@ namespace MonoTests.System.Web.UI.WebControls
 		}
 
 		[Test]
-		[Category ("NotWorking")]
 		[Category ("NunitWeb")]
 		public void DetailsView_PagingPostback ()
 		{
@@ -1415,7 +1414,6 @@ namespace MonoTests.System.Web.UI.WebControls
 		#endregion
 		
 		[Test]
-		[Category ("NotWorking")]
 		[Category ("NunitWeb")]
 		public void DetailsView_DeletePostback ()
 		{