DetailsView.ModeChanging イベント

定義

DetailsView コントロールが編集、挿入、および読み取り専用の各モード間の切り替えを行おうとした場合に、CurrentMode プロパティの更新前に発生します。

C#
public event System.Web.UI.WebControls.DetailsViewModeEventHandler ModeChanging;

イベントの種類

次のコード例では、 イベントを ModeChanging 使用して、コントロールが編集モードのときにページング機能を無効にする方法を DetailsView 示します。

ASP.NET (C#)

<%@ 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>

注釈

イベントは ModeChanging 、コントロールが編集モード、挿入モード、読み取り専用モードの間で変更を試みたが DetailsView 、 プロパティが更新される前に発生します CurrentMode 。 これにより、このイベントが発生するたびに、モード変更のキャンセルなどのカスタム ルーチンを実行するイベント ハンドラーを提供できます。

DetailsViewModeEventArgsオブジェクトがイベント ハンドラーに渡されます。これにより、新しいモードを決定したり、ユーザーが編集操作を取り消した結果モードの変更であったかどうかを判断したり、モード変更を取り消したりできます。 新しいモードを確認するには、 プロパティを使用します NewMode 。 モード変更がユーザーが編集操作を取り消した結果であるかどうかを判断するには、 プロパティを CancelingEdit 使用します。 モードの変更を取り消すには、 プロパティを Canceltrue設定します。

イベントを処理する方法の詳細については、次を参照してください。処理とイベントの発生します。

適用対象

製品 バージョン
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

こちらもご覧ください