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


RowCommand イベントは、GridView コントロール内のボタンがクリックされた場合に発生します。これにより、このイベントが発生するたびにカスタム ルーチンを実行するイベント処理メソッドを提供できます。
![]() |
---|
GridView コントロールは、特定のボタン (CommandName プロパティが "Delete"、"Update"、"Page" などに設定されたボタン) がクリックされたときに、他の特別なイベントも発生させます。これらのボタンのいずれかを使用する場合は、コントロールによって提供される特別なイベント (RowDeleted や RowDeleting など) のいずれかを処理することも考慮する必要があります。 |
GridViewCommandEventArgs オブジェクトがイベント処理メソッドに渡されることにより、クリックされたボタンのコマンド名およびコマンド引数を確認できます。コマンド名を確認するには CommandName プロパティを、コマンド引数を確認するには CommandArgument プロパティを使用します。CommandSource プロパティを使用して、イベントを発生させたボタン コントロールにアクセスすることもできます。
イベント処理の詳細については、「イベントの利用」を参照してください。
GridViewCommandEventArgs のインスタンスの初期プロパティ値の一覧については、GridViewCommandEventArgs コンストラクタのトピックを参照してください。

イベント処理メソッドに渡された GridViewCommandEventArgs オブジェクトを使用して、イベントを発生させたボタンのコマンド名を確認する方法を次の例に示します。
<%@ Page language="VB" %> <script runat="server"> Sub CustomersGridView_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) ' If multiple buttons are used in a GridView control, use the ' CommandName property to determine which button was clicked. If e.CommandName = "Add" Then ' Convert the row index stored in the CommandArgument ' property to an Integer. Dim index As Integer = Convert.ToInt32(e.CommandArgument) ' Retrieve the row that contains the button clicked ' by the user from the Rows collection. Dim row As GridViewRow = CustomersGridView.Rows(index) ' Create a new ListItem object for the customer in the row. Dim item As New ListItem() item.Text = Server.HtmlDecode(row.Cells(2).Text) ' If the customer is not already in the ListBox, add the ListItem ' object to the Items collection of the ListBox control. If Not CustomersListBox.Items.Contains(item) Then CustomersListBox.Items.Add(item) End If End If End Sub Sub CustomersGridView_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs) ' The GridViewCommandEventArgs class does not contain a ' property that indicates which row's command button was ' clicked. To identify which row's button was clicked, use ' the button's CommandArgument property by setting it to the ' row's index. If e.Row.RowType = DataControlRowType.DataRow Then ' Retrieve the LinkButton control from the first column. Dim addButton As LinkButton = CType(e.Row.Cells(0).Controls(0), LinkButton) ' Set the LinkButton's CommandArgument property with the ' row's index. addButton.CommandArgument = e.Row.RowIndex.ToString() End If End Sub </script> <html> <body> <form runat="server"> <h3>GridView RowCommand Example</h3> <table width="100%"> <tr> <td width="50%"> <asp:gridview id="CustomersGridView" datasourceid="CustomersSource" allowpaging="true" autogeneratecolumns="false" onrowcommand="CustomersGridView_RowCommand" onrowcreated="CustomersGridView_RowCreated" runat="server"> <columns> <asp:buttonfield buttontype="Link" commandname="Add" text="Add"/> <asp:boundfield datafield="CustomerID" headertext="Customer ID"/> <asp:boundfield datafield="CompanyName" headertext="Company Name"/> <asp:boundfield datafield="City" headertext="City"/> </columns> </asp:gridview> </td> <td valign="top" width="50%"> Customers: <br/> <asp:listbox id="CustomersListBox" runat="server"/> </td> </tr> </table> <!-- 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="CustomersSource" selectcommand="Select [CustomerID], [CompanyName], [City] From [Customers]" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void CustomersGridView_RowCommand(Object sender, GridViewCommandEventArgs e) { // If multiple buttons are used in a GridView control, use the // CommandName property to determine which button was clicked. if(e.CommandName=="Add") { // Convert the row index stored in the CommandArgument // property to an Integer. int index = Convert.ToInt32(e.CommandArgument); // Retrieve the row that contains the button clicked // by the user from the Rows collection. GridViewRow row = CustomersGridView.Rows[index]; // Create a new ListItem object for the customer in the row. ListItem item = new ListItem(); item.Text = Server.HtmlDecode(row.Cells[2].Text); // If the customer is not already in the ListBox, add the ListItem // object to the Items collection of the ListBox control. if (!CustomersListBox.Items.Contains(item)) { CustomersListBox.Items.Add(item); } } } void CustomersGridView_RowCreated(Object sender, GridViewRowEventArgs e) { // The GridViewCommandEventArgs class does not contain a // property that indicates which row's command button was // clicked. To identify which row's button was clicked, use // the button's CommandArgument property by setting it to the // row's index. if(e.Row.RowType == DataControlRowType.DataRow) { // Retrieve the LinkButton control from the first column. LinkButton addButton = (LinkButton)e.Row.Cells[0].Controls[0]; // Set the LinkButton's CommandArgument property with the // row's index. addButton.CommandArgument = e.Row.RowIndex.ToString(); } } </script> <html> <body> <form runat="server"> <h3>GridView RowCommand Example</h3> <table width="100%"> <tr> <td width="50%"> <asp:gridview id="CustomersGridView" datasourceid="CustomersSource" allowpaging="true" autogeneratecolumns="false" onrowcommand="CustomersGridView_RowCommand" onrowcreated="CustomersGridView_RowCreated" runat="server"> <columns> <asp:buttonfield buttontype="Link" commandname="Add" text="Add"/> <asp:boundfield datafield="CustomerID" headertext="Customer ID"/> <asp:boundfield datafield="CompanyName" headertext="Company Name"/> <asp:boundfield datafield="City" headertext="City"/> </columns> </asp:gridview> </td> <td valign="top" width="50%"> Customers: <br/> <asp:listbox id="CustomersListBox" runat="server"/> </td> </tr> </table> <!-- 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="CustomersSource" selectcommand="Select [CustomerID], [CompanyName], [City] From [Customers]" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>


System.EventArgs
System.Web.UI.WebControls.CommandEventArgs
System.Web.UI.WebControls.GridViewCommandEventArgs


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


GridViewCommandEventArgs コンストラクタ (GridViewRow, Object, CommandEventArgs)
アセンブリ: System.Web (system.web.dll 内)

Public Sub New ( _ row As GridViewRow, _ commandSource As Object, _ originalArgs As CommandEventArgs _ )
Dim row As GridViewRow Dim commandSource As Object Dim originalArgs As CommandEventArgs Dim instance As New GridViewCommandEventArgs(row, commandSource, originalArgs)
public GridViewCommandEventArgs ( GridViewRow row, Object commandSource, CommandEventArgs originalArgs )
public: GridViewCommandEventArgs ( GridViewRow^ row, Object^ commandSource, CommandEventArgs^ originalArgs )
public GridViewCommandEventArgs ( GridViewRow row, Object commandSource, CommandEventArgs originalArgs )
public function GridViewCommandEventArgs ( row : GridViewRow, commandSource : Object, originalArgs : CommandEventArgs )

このコンストラクタを使用して、GridViewCommandEventArgs クラスの新しいインスタンスを初期化します。
GridViewCommandEventArgs のインスタンスの初期プロパティ値を次の表に示します。
CommandArgument | originalArgs パラメータに格納された CommandEventArgs オブジェクトの CommandArgument プロパティ値。 |
CommandName | originalArgs パラメータに格納された CommandEventArgs オブジェクトの CommandName プロパティ値。 |
CommandSource |
![]() |
---|

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


GridViewCommandEventArgs コンストラクタ

名前 | 説明 |
---|---|
GridViewCommandEventArgs (Object, CommandEventArgs) | コマンドのソースとイベントの引数を指定して、GridViewCommandEventArgs クラスの新しいインスタンスを初期化します。 |
GridViewCommandEventArgs (GridViewRow, Object, CommandEventArgs) | 行、コマンドのソース、およびイベントの引数を指定して、GridViewCommandEventArgs クラスの新しいインスタンスを初期化します。 |

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

Dim commandSource As Object Dim originalArgs As CommandEventArgs Dim instance As New GridViewCommandEventArgs(commandSource, originalArgs)
public function GridViewCommandEventArgs ( commandSource : Object, originalArgs : CommandEventArgs )

このコンストラクタを使用して、GridViewCommandEventArgs クラスの新しいインスタンスを初期化します。
GridViewCommandEventArgs のインスタンスの初期プロパティ値を次の表に示します。
CommandArgument | originalArgs パラメータに格納された CommandEventArgs オブジェクトの CommandArgument プロパティ値。 |
CommandName | originalArgs パラメータに格納された CommandEventArgs オブジェクトの CommandName プロパティ値。 |
CommandSource |
![]() |
---|

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


GridViewCommandEventArgs プロパティ

名前 | 説明 | |
---|---|---|
![]() | CommandArgument | コマンドの引数を取得します。 ( CommandEventArgs から継承されます。) |
![]() | CommandName | コマンド名を取得します。 ( CommandEventArgs から継承されます。) |
![]() | CommandSource | コマンドのソースを取得します。 |

GridViewCommandEventArgs メソッド

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

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

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


名前 | 説明 | |
---|---|---|
![]() | CommandArgument | コマンドの引数を取得します。(CommandEventArgs から継承されます。) |
![]() | CommandName | コマンド名を取得します。(CommandEventArgs から継承されます。) |
![]() | CommandSource | コマンドのソースを取得します。 |

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

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

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

- GridViewCommandEventArgsのページへのリンク