DetailsView.ModeChanging Zdarzenie

Definicja

Występuje, gdy kontrolka DetailsView próbuje zmienić tryb edycji, wstawiania i tylko do odczytu, ale przed zaktualizowaną właściwością CurrentMode .

public:
 event System::Web::UI::WebControls::DetailsViewModeEventHandler ^ ModeChanging;
public event System.Web.UI.WebControls.DetailsViewModeEventHandler ModeChanging;
member this.ModeChanging : System.Web.UI.WebControls.DetailsViewModeEventHandler 
Public Custom Event ModeChanging As DetailsViewModeEventHandler 

Typ zdarzenia

Przykłady

W poniższym przykładzie kodu pokazano, jak za pomocą ModeChanging zdarzenia wyłączyć funkcję stronicowania, gdy kontrolka DetailsView jest w trybie edycji.


<%@ Page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    void CustomerDetailView_ModeChanging(Object sender, DetailsViewModeEventArgs e)
  {
    // Disable the paging feature in edit mode.
    if (e.NewMode == DetailsViewMode.Edit)
    {
        CustomerDetailView.AllowPaging = false;
    }
    else
    {
        CustomerDetailView.AllowPaging = true;
    }
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsView ModeChanging Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView ModeChanging Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneraterows="true"
          autogenerateeditbutton="true" 
          allowpaging="true"
          onmodechanging="CustomerDetailView_ModeChanging" 
          runat="server">
               
          <fieldheaderstyle backcolor="Navy"
            forecolor="White"/>
                    
        </asp:detailsview>
        
        <!-- 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" 
          ConnectionString=
            "<%$ 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 
            [Customers]">
        </asp:SqlDataSource>
    </form>
  </body>
</html>

<%@ Page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    Sub CustomerDetailView_ModeChanging(ByVal sender As Object, ByVal e As DetailsViewModeEventArgs)
        ' Disable the paging feature in edit mode.
        If e.NewMode = DetailsViewMode.Edit Then
            CustomerDetailView.AllowPaging = False
        Else
            CustomerDetailView.AllowPaging = True
        End If
    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsView ModeChanging Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView ModeChanging Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneraterows="true"
          autogenerateeditbutton="true" 
          allowpaging="true"
          onmodechanging="CustomerDetailView_ModeChanging" 
          runat="server">
               
          <fieldheaderstyle backcolor="Navy"
            forecolor="White"/>
                    
        </asp:detailsview>
        
        <!-- 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" 
          ConnectionString=
            "<%$ 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 
            [Customers]">
        </asp:SqlDataSource>
    </form>
  </body>
</html>

Uwagi

Zdarzenie jest zgłaszane, gdy kontrolka ModeChanging próbuje zmienić tryb edycji, wstawiania i tylko do odczytu, ale przed zaktualizowaną właściwościąCurrentMode.DetailsView Dzięki temu można udostępnić procedurę obsługi zdarzeń, która wykonuje niestandardową procedurę, taką jak anulowanie zmiany trybu, za każdym razem, gdy wystąpi to zdarzenie.

DetailsViewModeEventArgs Obiekt jest przekazywany do procedury obsługi zdarzeń, która pozwala określić nowy tryb, aby określić, czy zmiana trybu była wynikiem anulowania operacji edycji przez użytkownika, czy anulowania zmiany trybu. Aby określić nowy tryb, użyj NewMode właściwości . Aby określić, czy zmiana trybu była wynikiem anulowania operacji edycji przez użytkownika, użyj CancelingEdit właściwości . Możesz anulować zmianę trybu, ustawiając Cancel właściwość na true.

Aby uzyskać więcej informacji na temat obsługi zdarzeń, zobacz Obsługa i podnoszenie zdarzeń.

Dotyczy

Zobacz też