Exception Property

FormViewDeletedEventArgs.Exception Property


Gets the exception (if any) that was raised during the delete operation.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

Public ReadOnly Property Exception As Exception

Property Value

Type: System.Exception

An Exception that represents the exception that was raised during the delete operation.

Use the Exception property to determine the exception (if any) that was raised during the delete operation. If no exceptions were raised, this property returns null.


If an exception was raised and you decide to handle the exception in the event handler, be sure to set the ExceptionHandled property to true; otherwise, the FormView control re-throws the exception.

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

<%@ Page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

  Sub EmployeeFormView_ItemDeleted(ByVal sender As Object, ByVal e As FormViewDeletedEventArgs) Handles EmployeeFormView.ItemDeleted

    ' Use the Exception property to determine whether an exception
    ' occurred during the delete operation.
    If e.Exception Is Nothing Then

      ' Use the AffectedRows property to determine whether the
      ' record was deleted. Sometimes an error might occur that 
      ' does not raise an exception, but prevents the delete
      ' operation from completing.
      If e.AffectedRows = 1 Then

        MessageLabel.Text = "Record deleted successfully."


        MessageLabel.Text = "An error occurred during the delete operation."

      End If


      ' 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

    End If

  End Sub


<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>FormViewDeletedEventArgs Example</title>
    <form id="form1" runat="server">

      <h3>FormViewDeletedEventArgs Example</h3>

      <asp:formview id="EmployeeFormView"


                <asp:image id="EmployeeImage"
                  imageurl='<%# Eval("PhotoPath") %>'
                  alternatetext='<%# Eval("LastName") %>' 
                <h3><%# Eval("FirstName") %>&nbsp;<%# Eval("LastName") %></h3>      
                <%# Eval("Title") %>        
              <td colspan="2">
                <asp:button id="DeleteButton"
                  text="Delete Record"
                  runat="server" />



      <asp:label id="MessageLabel"

      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file.                            -->
      <asp:sqldatasource id="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees]"
        deletecommand="Delete [Employees] Where [EmployeeID]=@EmployeeID"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 


.NET Framework
Available since 2.0
Return to top
© 2015 Microsoft