GridViewDeleteEventHandler デリゲート
アセンブリ: System.Web (system.web.dll 内)

Public Delegate Sub GridViewDeleteEventHandler ( _ sender As Object, _ e As GridViewDeleteEventArgs _ )
/** @delegate */ public delegate void GridViewDeleteEventHandler ( Object sender, GridViewDeleteEventArgs e )

GridView コントロールは、Delete ボタン (CommandName プロパティが "Delete" に設定されたボタン) がクリックされた場合に、GridView コントロールでレコードを削除する前に RowDeleting イベントを発生させます。これにより、このイベントが発生するたびにカスタム ルーチン (削除操作のキャンセルなど) を実行するイベント処理メソッドを提供できます。
GridViewDeleteEventHandler デリゲートを作成する場合は、イベントを処理するメソッドを識別してください。イベントをイベント ハンドラに関連付けるには、デリゲートのインスタンスをイベントに追加します。デリゲートを削除しない限り、そのイベントが発生すると常にイベント ハンドラが呼び出されます。イベント ハンドラ デリゲートの詳細については、「イベントとデリゲート」を参照してください。

GridViewDeleteEventHandler デリゲートを、プログラムによって GridView コントロールの RowDeleting イベントに追加する方法を次の例に示します。
<%@ Page language="VB" %> <script runat="server"> Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) ' Create a new GridView control. Dim customersGridView As New GridView() ' Set the GridView control's properties. customersGridView.ID = "CustomersGridView" customersGridView.DataSourceID = "CustomersSqlDataSource" customersGridView.AutoGenerateColumns = True customersGridView.AutoGenerateDeleteButton = True Dim keyArray() As String = {"CustomerID"} customersGridView.DataKeyNames = keyArray ' Programmatically register the event-handling methods. AddHandler customersGridView.RowDeleting, AddressOf CustomersGridView_RowDeleting ' Add the GridView object to the Controls collection ' of the PlaceHolder control. GridViewPlaceHolder.Controls.Add(customersGridView) End Sub Sub CustomersGridView_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs) ' User the sender parameter to retrieve the GridView control ' that raised the event. Dim customersGridView As GridView = CType(sender, GridView) ' 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>GridViewDeleteEventHandler Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <br/> <asp:placeholder id="GridViewPlaceHolder" 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="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 Page_Load(Object sender, EventArgs e) { // Create a new GridView control. GridView customersGridView = new GridView(); // Set the GridView control's properties. customersGridView.ID = "CustomersGridView"; customersGridView.DataSourceID = "CustomersSqlDataSource"; customersGridView.AutoGenerateColumns = true; customersGridView.AutoGenerateDeleteButton = true; customersGridView.DataKeyNames = new String[] {"CustomerID"}; // Programmatically register the event-handling methods. customersGridView.RowDeleting += new GridViewDeleteEventHandler(this.CustomersGridView_RowDeleting); // Add the GridView object to the Controls collection // of the PlaceHolder control. GridViewPlaceHolder.Controls.Add(customersGridView); } void CustomersGridView_RowDeleting(Object sender, GridViewDeleteEventArgs e) { // User the sender parameter to retrieve the GridView control // that raised the event. GridView customersGridView = (GridView)sender; // 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>GridViewDeleteEventHandler Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <br/> <asp:placeholder id="GridViewPlaceHolder" 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="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>
GridViewDeleteEventHandler デリゲートを、宣言によって GridView コントロールの RowDeleting イベントに追加する方法を次の例に示します。
<%@ 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に収録されているすべての辞書からGridViewDeleteEventHandler デリゲートを検索する場合は、下記のリンクをクリックしてください。

- GridViewDeleteEventHandler デリゲートのページへのリンク