DetailsView.AutoGenerateDeleteButton プロパティ

定義

現在のレコードを削除するための組み込みのコントロールを DetailsView コントロールに表示するかどうかを示す値を取得または設定します。

public:
 virtual property bool AutoGenerateDeleteButton { bool get(); void set(bool value); };
public virtual bool AutoGenerateDeleteButton { get; set; }
member this.AutoGenerateDeleteButton : bool with get, set
Public Overridable Property AutoGenerateDeleteButton As Boolean

プロパティ値

現在のレコードを削除するための組み込みのコントロールを表示する場合は true。それ以外の場合は false。 既定値は、false です。

次のコード例では、 プロパティを使用 AutoGenerateDeleteButton して組み込みコントロールを表示し、現在のレコードを削除する方法を示します。


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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsView AutoGenerateDeleteButton Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView AutoGenerateDeleteButton Example</h3>
                
        <asp:detailsview id="CustomersDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneratedeletebutton="true"  
          autogeneraterows="true"
          allowpaging="true"  
          runat="server">
               
          <headerstyle 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">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsView AutoGenerateDeleteButton Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView AutoGenerateDeleteButton Example</h3>
                
        <asp:detailsview id="CustomersDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneratedeletebutton="true"  
          autogeneraterows="true"
          allowpaging="true"  
          runat="server">
               
          <headerstyle 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>

注釈

コントロールが DetailsViewDataSourceView継承するオブジェクトにバインドされCanDelete、 プロパティが を返trueDetailsViewす場合、コントロールはデータ ソース コントロールの機能を利用し、自動削除機能を提供できます。

注意

オブジェクトが SqlDataSourceView データを削除するには、 SqlDataSource.DeleteCommand 基になる SqlDataSource オブジェクトの プロパティを delete クエリ ステートメントで設定する必要があります。

プロパティが AutoGenerateDeleteButtontrue設定されている場合、Delete ボタンを CommandField 含む行フィールドがコントロールに自動的に DetailsView 表示されます。 [削除] ボタンをクリックすると、そのレコードがデータ ソースから完全に削除されます。

Note

自動削除機能を DataKeyNames 機能させるには、 プロパティも設定する必要があります。

コントロールには DetailsView 、レコードが削除されたときにカスタム アクションを実行するために使用できるいくつかのイベントが用意されています。 次の表に、使用可能なイベントの一覧を示します。

Event 説明
ItemDeleted [削除] ボタンをクリックしたときに、コントロールが DetailsView データ ソースからレコードを削除した後に発生します。 このイベントは、多くの場合、削除操作の結果を確認するために使用されます。
ItemDeleting [削除] ボタンをクリックしたときに、コントロールがデータ ソースからレコードを削除する前に DetailsView 発生します。 このイベントは、削除操作を取り消すためによく使用されます。

AutoGenerateDeleteButton 値はビューステートに格納されます。

適用対象

こちらもご覧ください