Fired event RowDeleting which wasn’t handled

I’ve dusted off the old ASP.NET skills and have been putting in some hours on UI work.  I’m encountering a few oddities as I go such as this one.  I found some of my asp:GridView controls were throwing the below error when removing an item from the bound data source.

[HttpException (0x80004005): The GridView ‘Schema_GridView’ fired event RowDeleting which wasn’t handled.]
   System.Web.UI.WebControls.GridView.OnRowDeleting(GridViewDeleteEventArgs e) +1324506
   System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex) +569
   System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +869
   System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument) +207
   System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

Note the below C# and pay attention to the command name.  Using the string “Delete” as a command name will trigger internal events causing the asp:GridView control to throw the above exception.  Change the command name and problem solved. 

ButtonField Delete_ButtonField = new ButtonField();
Delete_ButtonField.ButtonType = ButtonType.Link;
Delete_ButtonField.CommandName = "Delete";
Schema_GridView.Columns.Add(Delete_ButtonField);
Schema_GridView.DataBind();

Advertisements
This entry was posted in .NET. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s