DetailsView.ModeChanged Event

Note: This event is new in the .NET Framework version 2.0.

Occurs when a DetailsView control attempts to change between edit, insert, and read-only mode, but after the CurrentMode property is updated.

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

Public Event ModeChanged As EventHandler
Dim instance As DetailsView
Dim handler As EventHandler

AddHandler instance.ModeChanged, handler

/** @event */
public void add_ModeChanged (EventHandler value)

/** @event */
public void remove_ModeChanged (EventHandler value)

JScript supports the use of events, but not the declaration of new ones.

The ModeChanged event is raised when a DetailsView control attempts to change between edit, insert, and read-only mode, but after the CurrentMode property is updated. This allows you to provide an event handler that performs a custom routine, such as synchronizing the DetailsView control with another control, whenever this event occurs.

For more information about handling events, see Consuming Events.

The following code example demonstrates how to use the ModeChanged event to display the current mode in the header row.

<%@ Page language="VB" %>

<script runat="server">

    Sub CustomerDetailView_ModeChanged(ByVal sender As Object, ByVal e As EventArgs)
        ' Display the current mode in the header row.
        Select Case CustomerDetailView.CurrentMode

            Case DetailsViewMode.Edit
                CustomerDetailView.HeaderText = "Edit Mode"
                CustomerDetailView.HeaderStyle.ForeColor = System.Drawing.Color.Red
                CustomerDetailView.HeaderStyle.BackColor = System.Drawing.Color.LightGray

            Case DetailsViewMode.Insert
                CustomerDetailView.HeaderText = "Insert Mode"
                CustomerDetailView.HeaderStyle.ForeColor = System.Drawing.Color.Green
                CustomerDetailView.HeaderStyle.BackColor = System.Drawing.Color.Yellow

            Case DetailsViewMode.ReadOnly
                CustomerDetailView.HeaderText = "Read-Only Mode"
                CustomerDetailView.HeaderStyle.ForeColor = System.Drawing.Color.Blue
                CustomerDetailView.HeaderStyle.BackColor = System.Drawing.Color.White

            Case Else
                CustomerDetailView.HeaderText = "Error!"
        End Select
    End Sub

    <form id="Form1" runat="server">
      <h3>DetailsView ModeChanged Example</h3>      
        <asp:detailsview id="CustomerDetailView"
          headertext="Read-Only Mode" 
          <fieldheaderstyle backcolor="Navy"
          <headerstyle forecolor="Blue"/>
        <!-- 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="DetailsViewSource" runat="server" 
            "<%$ ConnectionStrings:NorthWindConnectionString%>"
            InsertCommand="INSERT INTO [Customers]([CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName, @Address, @City, @PostalCode, @Country)"
          SelectCommand="Select [CustomerID], [CompanyName], 
            [Address], [City], [PostalCode], [Country] From 

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions