DetailsViewDeleteEventArgs クラス
アセンブリ: System.Web (system.web.dll 内)


DetailsView コントロールは、コントロール内の Delete ボタン (CommandName プロパティが "Delete" に設定されたボタン) がクリックされた場合に、DetailsView コントロールが実際にレコードを削除する前に ItemDeleting イベントを発生させます。これにより、このイベントが発生するたびにカスタム ルーチン (削除前にレコードを検査するなど) を実行するイベント ハンドラを提供できます。
DetailsViewDeletedEventArgs オブジェクトがイベント ハンドラに渡され、これにより削除されるレコードのインデックスを確認したり、削除操作をキャンセルしたりする必要があることを示したりできます。レコードのインデックスを確認するには、RowIndex プロパティを使用します。削除操作をキャンセルするには、Cancel プロパティを true に設定します。また、Keys プロパティを使用してキー フィールドにアクセスしたり、Values プロパティを使用してキー以外のフィールドにアクセスしたりすることもできます。これらの値は、削除前にレコードを検査する場合に役立ちます。
![]() |
---|
Keys プロパティのキー フィールド値を変更できます。これらの値を変更すると、新しいキー フィールド値に対応するレコードが削除されます。 |
イベント処理の詳細については、「イベントの利用」を参照してください。
DetailsViewDeleteEventArgs クラスのインスタンスの初期プロパティ値の一覧については、DetailsViewDeleteEventArgs コンストラクタのトピックを参照してください。

ItemDeleting イベントのイベント ハンドラに渡される DetailsViewDeleteEventArgs オブジェクトを使用して、削除操作をキャンセルする方法のコード例を次に示します。
<%@ Page language="VB" %> <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> <body> <form 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="C#" %> <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> <body> <form 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>


System.EventArgs
System.ComponentModel.CancelEventArgs
System.Web.UI.WebControls.DetailsViewDeleteEventArgs


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DetailsViewDeleteEventArgs コンストラクタ
アセンブリ: System.Web (system.web.dll 内)


このコンストラクタを使用して、DetailsViewDeleteEventArgs クラスの新しいインスタンスを初期化します。
DetailsViewDeleteEventArgs クラスのインスタンスの初期プロパティ値を次の表に示します。
![]() |
---|

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DetailsViewDeleteEventArgs プロパティ

名前 | 説明 | |
---|---|---|
![]() | Cancel | イベントをキャンセルするかどうかを示す値を取得または設定します。 ( CancelEventArgs から継承されます。) |
![]() | Keys | 削除される項目のキー フィールドの名前と値を格納している、キー フィールドの名前/値ペアの番号付きディクショナリを取得します。 |
![]() | RowIndex | 削除される行のインデックスを取得します。 |
![]() | Values | 削除する項目のキー以外のフィールドの名前と値のペアのディクショナリを取得します。 |

DetailsViewDeleteEventArgs メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

DetailsViewDeleteEventArgs メンバ
DetailsViewDeleteEventArgs データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Cancel | イベントをキャンセルするかどうかを示す値を取得または設定します。(CancelEventArgs から継承されます。) |
![]() | Keys | 削除される項目のキー フィールドの名前と値を格納している、キー フィールドの名前/値ペアの番号付きディクショナリを取得します。 |
![]() | RowIndex | 削除される行のインデックスを取得します。 |
![]() | Values | 削除する項目のキー以外のフィールドの名前と値のペアのディクショナリを取得します。 |

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

- DetailsViewDeleteEventArgsのページへのリンク