Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

DetailsView.ModeChanged Event

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 EventHandler ModeChanged
<asp:DetailsView OnModeChanged="EventHandler" />

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="C#" %>

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

    void CustomerDetailView_ModeChanged(Object sender, EventArgs e)
    // Display the current mode in the header row.
      switch (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;
          CustomerDetailView.HeaderText = "Error!";


<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsView ModeChanged Example</title>
    <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 

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.