asp.net.ph

GridView.RowDeleted Event

System.Web.UI.WebControls Namespace   GridView Class


.NET Framework version 2.0

Occurs when a Delete command button within a GridView control is clicked, but after the delete operation.

[ VB ]
Public Event RowDeleted As GridViewDeletedEventHandler

[ C# ]
public event GridViewDeletedEventHandler RowDeleted;

[ C++ ]
public: __event GridViewDeletedEventHandler* RowDeleted;

In [ JScript ], you can handle the events defined by a class, but you cannot define your own.

Remarks

The RowDeleted event is raised whenever a Delete button associated with an item in the GridView control is clicked, but after the GridView control deletes the record.

This allows you to provide an event-handling method that performs a custom routine, such as checking the results of a delete operation, whenever this event occurs.

Event Data

Information related to the RowDeleted event is passed via a GridViewDeletedEventArgs object to the method assigned to handle the event. The following GridViewDeletedEventArgs properties provide information specific to this event.

Property Description
AffectedRows Gets the number of rows affected by the delete operation.
Exception Gets the exception ( if any ) that was raised during the delete operation.
ExceptionHandled Gets or sets a value indicating whether an exception that was raised during the delete operation was handled in the event handler.
Keys Gets an ordered dictionary of key field name/value pairs for the deleted record.
Values Gets a dictionary of the non-key field name/value pairs for the deleted record.

Example

The following example demonstrates how to use the RowDeleted event to determine whether an exception occurred during a delete operation.

<script language = "C#" runat = "server">

   void EmployeeGridView_RowDeleted ( Object src, GridViewDeletedEventArgs e ) {
      // Use the Exception property to determine whether 
      // an exception occurred during the delete operation.
      if ( e.Exception == null ) {
         // Use the AffectedRows property to determine whether the record was deleted.
         // Sometimes an error might occur but does not raise an exception,
         // yet prevents the delete operation from completing.
         if ( e.AffectedRows == 1 ) {
            MessageLabel.Text = "Record deleted successfully.";
         } else {
            MessageLabel.Text = "An error occurred during the delete operation.";
         }
      } else {
         // Insert the code to handle the exception.
         MessageLabel.Text = e.Exception.Message;

         // Use the ExceptionHandled property to indicate
         // that the exception has already been handled.
         e.ExceptionHandled = true;
      }
   }

</script>
  C# VB

See Also

GridView Members   Allowing Users to Delete Rows in a GridView Control Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph