DetailsViewDeleteEventArgs DetailsViewDeleteEventArgs DetailsViewDeleteEventArgs DetailsViewDeleteEventArgs Class

定義

ItemDeleting イベントのデータを提供します。Provides data for the ItemDeleting event.

public ref class DetailsViewDeleteEventArgs : System::ComponentModel::CancelEventArgs
public class DetailsViewDeleteEventArgs : System.ComponentModel.CancelEventArgs
type DetailsViewDeleteEventArgs = class
    inherit CancelEventArgs
Public Class DetailsViewDeleteEventArgs
Inherits CancelEventArgs
継承
DetailsViewDeleteEventArgsDetailsViewDeleteEventArgsDetailsViewDeleteEventArgsDetailsViewDeleteEventArgs

次のコード例は、使用する方法を示します、DetailsViewDeleteEventArgsオブジェクトのイベント ハンドラーに渡される、 ItemDeleting delete 操作をキャンセルするイベントです。The following code example demonstrates how to use the DetailsViewDeleteEventArgs object passed to the event handler for the ItemDeleting event to cancel a delete operation.


<%@ 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 CustomerDetailsView_ItemDeleting(Object sender, 
    DetailsViewDeleteEventArgs e)
  {

    // Get customer ID and name from the Keys and Values
    // properties.
    String keyValue = e.Keys["CustomerID"].ToString();
    String customerName = e.Values["CompanyName"].ToString();

    // Cancel the delete operation if the user attempts to 
    // delete protected record. In this example, records
    // with a customer ID that starts with with "A" cannot
    // be deleted.
    if (keyValue.StartsWith("A"))
    {
      e.Cancel = true;
      MessageLabel.Text = "You cannot delete " +
        customerName + ". This customer is protected.";
    }
    else
    {
      MessageLabel.Text = "Row " + e.RowIndex.ToString() + 
        " deleted.";
    }

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsViewDeleteEventArgs Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DetailsViewDeleteEventArgs Example</h3>
                
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneratedeletebutton="true"  
          autogeneraterows="true"
          allowpaging="true"
          onitemdeleting="CustomerDetailsView_ItemDeleting" 
          runat="server">
            
          <fieldheaderstyle backcolor="Navy"
            forecolor="White"/>
                    
        </asp:detailsview>
        
        <asp:label id="MessageLabel"
          forecolor="Red"
          runat="server"/>
            
        <!-- 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"
          selectcommand="Select [CustomerID], [CompanyName], [Address], 
            [City], [PostalCode], [Country] From [Customers]"
          deletecommand="Delete [Customers] 
            Where [CustomerID]=@CustomerID"
          connectionstring=
            "<%$ ConnectionStrings:NorthWindConnectionString%>" 
          runat="server"/>
            
      </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 CustomerDetailsView_ItemDeleting(ByVal sender As Object, _
    ByVal e As DetailsViewDeleteEventArgs)

    ' Get customer ID and name from the Keys and Values
    ' properties.
    Dim keyValue As String = e.Keys("CustomerID").ToString()
    Dim customerName As String = e.Values("CompanyName").ToString()

    ' Cancel the delete operation if the user attempts to 
    ' delete protected record. In this example, records
    ' with a customer ID that starts with with "A" cannot
    ' be deleted.
    If keyValue.StartsWith("A") Then

      e.Cancel = True
      MessageLabel.Text = "You cannot delete " & _
        customerName & ". This customer is protected."
    
    Else
    
      MessageLabel.Text = "Row " & e.RowIndex.ToString() & _
        " deleted."
    
    End If
    
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsViewDeleteEventArgs Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DetailsViewDeleteEventArgs Example</h3>
                
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneratedeletebutton="true"  
          autogeneraterows="true"
          allowpaging="true"
          onitemdeleting="CustomerDetailsView_ItemDeleting" 
          runat="server">
            
          <fieldheaderstyle backcolor="Navy"
            forecolor="White"/>
                    
        </asp:detailsview>
        
        <asp:label id="MessageLabel"
          forecolor="Red"
          runat="server"/>
            
        <!-- 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"
          selectcommand="Select [CustomerID], [CompanyName], [Address], 
            [City], [PostalCode], [Country] From [Customers]"
          deletecommand="Delete [Customers] 
            Where [CustomerID]=@CustomerID"
          connectionstring=
            "<%$ ConnectionStrings:NorthWindConnectionString%>" 
          runat="server"/>
            
      </form>
  </body>
</html>

注釈

DetailsView生成を制御、ItemDeletingイベントと削除 ボタン (付きのボタンのCommandNameプロパティが"Delete"に設定)、コントロール内をクリックする前に、DetailsView制御レコードを削除します。The DetailsView control raises the ItemDeleting event when a Delete button (a button with its CommandName property set to "Delete") within the control is clicked, but before the DetailsView control deletes the record. これにより、このイベントが発生するたびに、削除する前に、レコードの確認などのカスタムのルーチンを実行するイベント ハンドラーを提供できます。This allows you to provide an event handler that performs a custom routine, such as verifying a record before deleting it, whenever this event occurs.

ADetailsViewDeletedEventArgsオブジェクトが削除されるレコードのインデックスを確認して、削除操作をキャンセルするかを示すことができます、イベント ハンドラーに渡されます。A DetailsViewDeletedEventArgs object is passed to the event handler, which allows you to determine the index of the record being deleted and to indicate that the delete operation should be canceled. レコードのインデックスを調べるには、RowIndexプロパティ。To determine the index of a record, use the RowIndex property. 削除操作をキャンセルするには、設定、Cancelプロパティをtrueします。To cancel the delete operation, set the Cancel property to true. 使用しても、キー フィールドと非キー フィールドにアクセスすることができます、KeysValuesプロパティでは、それぞれします。You can also access the key fields and non-key fields by using the Keys and Values properties, respectively. これらの値は、削除する前に、レコードを確認したい場合に便利です。These values are useful if you want to verify the record before deleting it.

注意

キー フィールドの値を変更することは、Keysプロパティ。It is possible to modify the key field values in the Keys property. これらの値を変更する場合は、新しいキー フィールドの値に対応するレコードが削除されます。If you change these values, the record that corresponds to the new key field values will be deleted.

イベントを処理する方法の詳細については、次を参照してください。処理とイベントの発生します。For more information about how to handle events, see Handling and Raising Events.

インスタンスの初期プロパティ値の一覧についてはDetailsViewDeleteEventArgsクラスを参照してください、DetailsViewDeleteEventArgsコンス トラクター。For a list of initial property values for an instance of DetailsViewDeleteEventArgs class, see the DetailsViewDeleteEventArgs constructor.

コンストラクター

DetailsViewDeleteEventArgs(Int32) DetailsViewDeleteEventArgs(Int32) DetailsViewDeleteEventArgs(Int32) DetailsViewDeleteEventArgs(Int32)

DetailsViewDeleteEventArgs クラスの新しいインスタンスを初期化します。Initializes a new instance of the DetailsViewDeleteEventArgs class.

プロパティ

Cancel Cancel Cancel Cancel

イベントをキャンセルするかどうかを示す値を取得または設定します。Gets or sets a value indicating whether the event should be canceled.

(Inherited from CancelEventArgs)
Keys Keys Keys Keys

削除される項目のキー フィールドの名前と値を格納している、キー フィールドの名前/値ペアの番号付きディクショナリを取得します。Gets an ordered dictionary of key field name/value pairs that contains the names and values of the key fields of the deleted items.

RowIndex RowIndex RowIndex RowIndex

削除される行のインデックスを取得します。Gets the index of the row being deleted.

Values Values Values Values

削除する項目のキー以外のフィールドの名前と値のペアのディクショナリを取得します。Gets a dictionary of the non-key field name/value pairs for the item to delete.

メソッド

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

指定したオブジェクトが、現在のオブジェクトと等しいかどうかを判断します。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

既定のハッシュ関数として機能します。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

現在のオブジェクトを表す文字列を返します。Returns a string that represents the current object.

(Inherited from Object)

適用対象

こちらもご覧ください