ButtonField.CommandName プロパティ
アセンブリ: System.Web (system.web.dll 内)

Dim instance As ButtonField Dim value As String value = instance.CommandName instance.CommandName = value
/** @property */ public String get_CommandName () /** @property */ public void set_CommandName (String value)
ButtonField のボタンがクリックされたときに実行されるアクションの名前。

CommandName プロパティを使用して、"Add" や "Remove" などのコマンド名を、ButtonField オブジェクトのボタンに関連付けます。CommandName プロパティには、コマンド ボタンがクリックされたときに実行するアクションを識別する任意の文字列を設定できます。この設定を行うと、イベント ハンドラでプログラムによってそのコマンド名を特定し、適切なアクションを実行できます。
![]() |
---|
データ バインド コントロールは、特定のコマンド名を認識すると、そのコントロールの適切なイベントを自動的に発生させて処理します。次のコマンド名が認識されます。
ページングを呼び出すには、CommandName に "Page" を設定し、さらに格納されている Button コントロールの CommandArgument に "First"、"Last"、"Prev"、"Next"、またはページ番号を設定します。ただし、ButtonField コントロールの CommandArgument は必ず整数の列インデックスになるので、 ButtonField コントロールはページングの呼び出しには適していません。また、CommandName に "Sort" を設定すると並べ替えを呼び出すことができますが、ButtonField コントロールの CommandArgument プロパティは必ず整数の行インデックスになります。このため、ButtonField コントロールは、並べ替えの呼び出しには適していません。"Add"、"Remove" などのカスタム コマンド名を使用する場合、イベント コードを記述してコマンド名をチェックし、カスタム アクションを実行する必要があります。詳細については、「DataControlCommands」を参照してください。

CommandName プロパティを使用して、GridView コントロールの ButtonField オブジェクトのボタンのコマンド名を指定する方法を、次のコード例に示します。
<%@ Page language="VB" %> <script runat="server"> Sub CustomersGridView_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) ' If multiple ButtonField column fields are used, use the ' CommandName property to determine which button was clicked. If e.CommandName = "Select" Then ' Convert the row index stored in the CommandArgument ' property to an Integer. Dim index As Integer = Convert.ToInt32(e.CommandArgument) ' Get the last name of the selected author from the appropriate ' cell in the GridView control. Dim selectedRow As GridViewRow = CustomersGridView.Rows(index) Dim contactCell As TableCell = selectedRow.Cells(1) Dim contact As String = contactCell.Text ' Display the selected author. Message.Text = "You selected " & contact & "." End If End Sub </script> <html> <body> <form id="Form1" runat="server"> <h3>ButtonField Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <!-- Populate the Columns collection declaratively. --> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="false" onrowcommand="CustomersGridView_RowCommand" runat="server"> <columns> <asp:buttonfield buttontype="Button" commandname="Select" headertext="Select Customer" text="Select"/> <asp:boundfield datafield="CompanyName" headertext="Company Name"/> <asp:boundfield datafield="ContactName" headertext="Contact Name"/> </columns> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. --> <asp:sqldatasource id="CustomersSqlDataSource" selectcommand="Select [CustomerID], [CompanyName], [ContactName], [ContactTitle] From [Customers]" connectionstring="<%$ ConnectionStrings:NorthWindConnection%>" runat="server"> </asp:sqldatasource> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void CustomersGridView_RowCommand(Object sender, GridViewCommandEventArgs e) { // If multiple ButtonField column fields are used, use the // CommandName property to determine which button was clicked. if(e.CommandName=="Select") { // Convert the row index stored in the CommandArgument // property to an Integer. int index = Convert.ToInt32(e.CommandArgument); // Get the last name of the selected author from the appropriate // cell in the GridView control. GridViewRow selectedRow = CustomersGridView.Rows[index]; TableCell contactName = selectedRow.Cells[1]; string contact = contactName.Text; // Display the selected author. Message.Text = "You selected " + contact + "."; } } </script> <html> <body> <form runat="server"> <h3>ButtonField Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <!-- Populate the Columns collection declaratively. --> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="false" onrowcommand="CustomersGridView_RowCommand" runat="server"> <columns> <asp:buttonfield buttontype="Button" commandname="Select" headertext="Select Customer" text="Select"/> <asp:boundfield datafield="CompanyName" headertext="Company Name"/> <asp:boundfield datafield="ContactName" headertext="Contact Name"/> </columns> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. --> <asp:sqldatasource id="CustomersSqlDataSource" selectcommand="Select [CustomerID], [CompanyName], [ContactName], [ContactTitle] From [Customers]" connectionstring="<%$ ConnectionStrings:NorthWindConnection%>" 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に収録されているすべての辞書からButtonField.CommandName プロパティを検索する場合は、下記のリンクをクリックしてください。

- ButtonField.CommandName プロパティのページへのリンク