GridViewCancelEditEventArgs クラス
アセンブリ: System.Web (system.web.dll 内)
構文
解説GridView コントロールは、Cancel ボタン (CommandName プロパティが "Cancel" に設定されたボタン) がクリックされた場合に、編集モードを終了する前に RowCancelingEdit イベントを発生させます。これにより、このイベントが発生するたびにカスタム ルーチン (行が好ましくない状態になった場合にキャンセル操作を停止するなど) を実行するイベント処理メソッドを提供できます。
GridViewCancelEditEventArgs オブジェクトがイベント処理メソッドに渡されることにより、イベントを発生させた Cancel ボタンが格納されている行のインデックスを確認したり、キャンセル操作を停止する必要があることを示したりできます。キャンセル操作を停止するには、Cancel プロパティを true に設定します。
イベント処理の詳細については、「イベントの利用」を参照してください。
GridViewCancelEditEventArgs のインスタンスの初期プロパティ値の一覧については、GridViewCancelEditEventArgs コンストラクタのトピックを参照してください。
使用例イベント処理メソッドに渡された GridViewCancelEditEventArgs オブジェクトを使用して、ユーザーがクリックした Cancel ボタンが格納されている行のインデックスを確認する方法を次の例に示します。
<%@ Page language="VB" %> <script runat="server"> Sub CustomersGridView_RowCancelingEdit(ByVal sender As Object, ByVal e As GridViewCancelEditEventArgs) ' Retrieve the row that raised the event from the Rows ' collection of the GridView control. Dim row As GridViewRow = CustomersGridView.Rows(e.RowIndex) ' The update operation was canceled. Display the ' primary key of the row. In this example, the primary ' key is displayed in the second column of the GridView ' control. To access the text of the column, use the Cells ' collection of the row. Message.Text = "Update for item " & row.Cells(1).Text & " Canceled." End Sub Sub CustomersGridView_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs) ' The GridView control is entering edit mode. Clear the message label. Message.Text = "" End Sub Sub CustomersGridView_RowUpdated(ByVal sender As Object, ByVal e As GridViewUpdatedEventArgs) ' The update operation was successful. Clear the message label. Message.Text = "" End Sub </script> <html> <body> <form runat="server"> <h3>GridView RowCancelingEdit Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <br/> <!-- The GridView control automatically sets the columns --> <!-- specified in the datakeynames attribute as read-only. --> <!-- No input controls are rendered for these columns in --> <!-- edit mode. --> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="true" autogenerateeditbutton="true" allowpaging="true" datakeynames="CustomerID" onrowcancelingedit="CustomersGridView_RowCancelingEdit" onrowediting="CustomersGridView_RowEditing" onrowupdated="CustomersGridView_RowUpdated" 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]" updatecommand="Update Customers SET CompanyName=@CompanyName, Address=@Address, City=@City, PostalCode=@PostalCode, Country=@Country WHERE (CustomerID = @CustomerID)" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"> </asp:sqldatasource> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void CustomersGridView_RowCancelingEdit(Object sender, GridViewCancelEditEventArgs e) { // Retrieve the row that raised the event from the Rows // collection of the GridView control. GridViewRow row = CustomersGridView.Rows[e.RowIndex]; // The update operation was canceled. Display the // primary key of the row. In this example, the primary // key is displayed in the second column of the GridView // control. To access the text of the column, use the Cells // collection of the row. Message.Text = "Update for item " + row.Cells[1].Text + " Canceled."; } void CustomersGridView_RowEditing(Object sender, GridViewEditEventArgs e) { // The GridView control is entering edit mode. Clear the message label. Message.Text = ""; } void CustomersGridView_RowUpdated(Object sender, GridViewUpdatedEventArgs e) { // The update operation was successful. Clear the message label. Message.Text = ""; } </script> <html> <body> <form runat="server"> <h3>GridView RowCancelingEdit Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <br/> <!-- The GridView control automatically sets the columns --> <!-- specified in the datakeynames attribute as read-only. --> <!-- No input controls are rendered for these columns in --> <!-- edit mode. --> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="true" autogenerateeditbutton="true" allowpaging="true" datakeynames="CustomerID" onrowcancelingedit="CustomersGridView_RowCancelingEdit" onrowediting="CustomersGridView_RowEditing" onrowupdated="CustomersGridView_RowUpdated" 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]" updatecommand="Update Customers SET CompanyName=@CompanyName, Address=@Address, City=@City, PostalCode=@PostalCode, Country=@Country WHERE (CustomerID = @CustomerID)" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"> </asp:sqldatasource> </form> </body> </html>
.NET Framework のセキュリティ
継承階層System.EventArgs
System.ComponentModel.CancelEventArgs
System.Web.UI.WebControls.GridViewCancelEditEventArgs
スレッド セーフ
プラットフォーム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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照GridViewCancelEditEventArgs コンストラクタ
アセンブリ: System.Web (system.web.dll 内)
構文
解説このコンストラクタを使用して、GridViewCancelEditEventArgs クラスの新しいインスタンスを初期化します。
GridViewCancelEditEventArgs のインスタンスの初期プロパティ値を次の表に示します。
メモ |
|---|
プラットフォーム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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
参照GridViewCancelEditEventArgs プロパティ
パブリック プロパティ| 名前 | 説明 | |
|---|---|---|
| Cancel | イベントをキャンセルするかどうかを示す値を取得または設定します。 ( CancelEventArgs から継承されます。) |
| RowIndex | イベントを発生させた Cancel ボタンが格納されている行のインデックスを取得します。 |
参照GridViewCancelEditEventArgs メソッド
パブリック メソッド| 名前 | 説明 | |
|---|---|---|
| Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
| GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
| GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
| ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
| ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |
プロテクト メソッド| 名前 | 説明 | |
|---|---|---|
| Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
| MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |
参照GridViewCancelEditEventArgs メンバ
RowCancelingEdit イベントのデータを提供します。
GridViewCancelEditEventArgs データ型で公開されるメンバを以下の表に示します。
パブリック コンストラクタ
パブリック プロパティ| 名前 | 説明 | |
|---|---|---|
| Cancel | イベントをキャンセルするかどうかを示す値を取得または設定します。(CancelEventArgs から継承されます。) |
| RowIndex | イベントを発生させた Cancel ボタンが格納されている行のインデックスを取得します。 |
パブリック メソッド| 名前 | 説明 | |
|---|---|---|
| Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
| GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
| GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
| ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
| ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |
プロテクト メソッド| 名前 | 説明 | |
|---|---|---|
| Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
| MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |
参照- GridViewCancelEditEventArgsのページへのリンク
.gif)