GridView.RowDeleting イベント
アセンブリ: System.Web (system.web.dll 内)

Dim instance As GridView Dim handler As GridViewDeleteEventHandler AddHandler instance.RowDeleting, handler
public: event GridViewDeleteEventHandler^ RowDeleting { void add (GridViewDeleteEventHandler^ value); void remove (GridViewDeleteEventHandler^ value); }

RowDeleting イベントは、行の Delete ボタンがクリックされた場合に、GridView コントロールが行を削除する前に発生します。これにより、このイベントが発生するたびにカスタム ルーチン (削除操作のキャンセルなど) を実行するイベント処理メソッドを提供できます。
GridViewDeleteEventArgs オブジェクトがイベント処理メソッドに渡されることにより、現在の行のインデックスを確認したり、削除操作をキャンセルする必要があることを示したりできます。削除操作をキャンセルするには、GridViewDeleteEventArgs オブジェクトの Cancel プロパティを true に設定します。また、必要に応じて、値がデータ ソースに渡される前に Keys コレクションと Values コレクションを操作することもできます。

RowDeleting イベントを使用して、ユーザーが GridView コントロールの最後のレコードを削除しようとした場合に削除操作をキャンセルする方法を次のコード例に示します。
<%@ Page language="VB" %> <script runat="server"> Sub CustomersGridView_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs) ' Cancel the delete operation if the user attempts to remove ' the last record from the GridView control. If CustomersGridView.Rows.Count <= 1 Then e.Cancel = True Message.Text = "You must keep at least one record." End If End Sub </script> <html> <body> <form runat="server"> <h3>GridView RowDeleting Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <br/> <!-- The GridView control automatically sets the columns --> <!-- specified in the datakeynames property as read-only. --> <!-- No input controls are rendered for these columns in --> <!-- edit mode. --> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="true" autogeneratedeletebutton="true" datakeynames="CustomerID" onrowdeleting="CustomersGridView_RowDeleting" runat="server"> </asp:gridview> <!-- 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="CustomersSqlDataSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" deletecommand="Delete from Customers where CustomerID = @CustomerID" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"> </asp:sqldatasource> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void CustomersGridView_RowDeleting(Object sender, GridViewDeleteEventArgs e) { // Cancel the delete operation if the user attempts to remove // the last record from the GridView control. if (CustomersGridView.Rows.Count <= 1) { e.Cancel = true; Message.Text = "You must keep at least one record."; } } </script> <html> <body> <form runat="server"> <h3>GridView RowDeleting Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <br/> <!-- The GridView control automatically sets the columns --> <!-- specified in the datakeynames property as read-only. --> <!-- No input controls are rendered for these columns in --> <!-- edit mode. --> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="true" autogeneratedeletebutton="true" datakeynames="CustomerID" onrowdeleting="CustomersGridView_RowDeleting" runat="server"> </asp:gridview> <!-- 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="CustomersSqlDataSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" deletecommand="Delete from Customers where CustomerID = @CustomerID" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"> </asp:sqldatasource> </form> </body> </html>

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からGridView.RowDeleting イベントを検索する場合は、下記のリンクをクリックしてください。

- GridView.RowDeleting イベントのページへのリンク