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


ItemCommand イベントは、FormView コントロール内のボタン コントロールがクリックされた場合に発生します。これにより、このイベントが発生するたびにカスタム ルーチンを実行するイベント処理メソッドを提供できます。
FormView コントロール内のボタンから、コントロールの組み込み機能の一部を呼び出すこともできます。これらのいずれかの操作を実行するには、ボタンの CommandName プロパティを次の表の値のいずれかに設定します。
CommandName 値 | |
---|---|
"Cancel" | 編集操作または挿入操作をキャンセルし、FormView コントロールを DefaultMode プロパティで指定されたモードに戻します。ModeChanged イベントおよび ModeChanging イベントを発生させます。 |
"Delete" | |
"Edit" | FormView コントロールを編集モードにします。ModeChanged イベントおよび ModeChanging イベントを発生させます。 |
"Insert" | 現在のレコードをデータ ソースに挿入します。ItemInserted イベントおよび ItemInserting イベントを発生させます。 |
"New" | FormView コントロールを挿入モードにします。ModeChanged イベントおよび ModeChanging イベントを発生させます。 |
"Page" | ページング操作を実行します。ボタンの CommandArgument プロパティを "First"、"Last"、"Next"、"Prev"、またはページ番号に設定して、実行するページング操作の種類を指定します。PageIndexChanged イベントおよび PageIndexChanging イベントを発生させます。 |
"Update" | 現在のレコードをデータ ソースで更新します。ItemUpdated イベントおよび ItemUpdating イベントを発生させます。 |
前述の表に示されているボタンがクリックされると ItemCommand イベントが発生しますが、表に示されているイベントを使用して操作を行うことをお勧めします。
FormViewCommandEventArgs オブジェクトがイベント処理メソッドに渡されることにより、クリックされたボタンのコマンド名およびコマンド引数を確認できます。コマンド名を確認するには CommandName プロパティを、コマンド引数を確認するには CommandArgument プロパティを使用します。CommandSource プロパティを使用して、イベントを発生させたボタン コントロールにアクセスすることもできます。
イベント処理の詳細については、「イベントの利用」を参照してください。
FormViewCommandEventArgs クラスのインスタンスの初期プロパティ値の一覧については、FormViewCommandEventArgs コンストラクタのトピックを参照してください。

ItemCommand イベントのイベント処理メソッドに渡された FormViewCommandEventArgs オブジェクトを使用して、ユーザーがクリックした FormView コントロール内のボタンを確認する方法を次の例に示します。
<%@ Page language="VB" %> <script runat="server"> Sub ProductFormView_ItemCommand(ByVal sender As Object, ByVal e As FormViewCommandEventArgs) ' The ItemCommand event is raised when any button within ' the FormView control is clicked. Use the CommandName property ' to determine which button was clicked. If e.CommandName = "Add" Then ' Add the product to the ListBox control. ' Use the Row property to retrieve the data row. Dim row As FormViewRow = ProductFormView.Row ' Retrieve the ProductNameLabel control from ' the data row. Dim productNameLabel As Label = CType(row.FindControl("ProductNameLabel"), Label) ' Retrieve the QuantityTextBox control from ' the data row. Dim quantityTextBox As TextBox = CType(row.FindControl("QuantityTextBox"), TextBox) If productNameLabel IsNot Nothing And quantityTextBox IsNot Nothing Then ' Get the product name from the ProductNameLabel control. Dim name As String = productNameLabel.Text ' Get the quantity from the QuantityTextBox control. Dim quantity As String = quantityTextBox.Text ' Create the text to display in the ListBox control. Dim description As String = name & " - " & quantity & " Qty" ' Create a ListItem object using the description and ' product name. Dim item As new ListItem(description, name) ' Add the ListItem object to the ListBox. ProductListBox.Items.Add(item) ' Use the CommandSource property to retrieve ' the Add button. Disable the button after ' the user adds the currently displayed employee ' name to the ListBox control. Dim addButton As Button = CType(e.CommandSource, Button) addButton.Enabled = False End If End If End Sub Sub ProductFormView_DataBound(ByVal sender As Object, ByVal e As EventArgs) ' To prevent the user from adding duplicate items, ' disable the Add button if the item being bound to the ' FormView control is already in the ListBox control. ' Use the Row property to retrieve the data row. Dim row As FormViewRow = ProductFormView.Row ' Retrieve the Add button from the data row. Dim addButton As Button = CType(row.FindControl("AddButton"), Button) ' Retrieve the ProductNameLabel control from ' data row. Dim productNameLabel As Label = CType(row.FindControl("ProductNameLabel"), Label) If addButton IsNot Nothing And productNameLabel IsNot Nothing Then ' Get the product name from the ProductNameLabel ' control. Dim name As String = productNameLabel.Text ' Use the FindByValue method to determine whether ' the ListBox control already contains an entry for ' the item. Dim item As ListItem = ProductListBox.Items.FindByValue(name) ' Disable the Add button if the ListBox control ' already contains the item. If item IsNot Nothing Then addButton.Enabled = False Else addButton.Enabled = True End If End If End Sub </script> <html> <body> <form runat="server"> <h3>FormViewCommandEventArgs Example</h3> <asp:formview id="ProductFormView" datasourceid="ProductSource" allowpaging="true" datakeynames="ProductID" onitemcommand="ProductFormView_ItemCommand" ondatabound="ProductFormView_DataBound" runat="server"> <itemtemplate> <table> <tr> <td width="400px"> <b>Description:</b> <asp:label id="ProductNameLabel" text='<%# Eval("ProductName") %>' runat='server'/> <br/> <b>Price:</b> <asp:label id="PriceLabel" text='<%# Eval("UnitPrice", "{0:c}") %>' runat='server'/> <br/> <asp:textbox id="QuantityTextBox" width="50px" maxlength="3" runat="server"/> Qty </td> </tr> <tr> <td> <asp:requiredfieldvalidator ID="QuantityRequiredValidator" controltovalidate="QuantityTextBox" text="Please enter a quantity." display="Static" runat="server"/> <br/> <asp:CompareValidator id="QuantityCompareValidator" controltovalidate="QuantityTextBox" text="Please enter an integer value." display="Static" type="Integer" operator="DataTypeCheck" runat="server"/> </td> </tr> <tr> <td colspan="2"> <asp:button id="AddButton" text="Add" commandname="Add" runat="server"/> </td> </tr> </table> </itemtemplate> </asp:formview> <br/><br/><hr/> Items:<br/> <asp:listbox id="ProductListBox" 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="ProductSource" selectcommand="Select [ProductID], [ProductName], [UnitPrice] From [Products]" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>
<%@ Page language="C#" %> <script runat="server"> void ProductFormView_ItemCommand(Object sender, FormViewCommandEventArgs e) { // The ItemCommand event is raised when any button within // the FormView control is clicked. Use the CommandName property // to determine which button was clicked. if (e.CommandName == "Add") { // Add the product to the ListBox control. // Use the Row property to retrieve the data row. FormViewRow row = ProductFormView.Row; // Retrieve the ProductNameLabel control from // the data row. Label productNameLabel = (Label)row.FindControl("ProductNameLabel"); // Retrieve the QuantityTextBox control from // the data row. TextBox quantityTextBox = (TextBox)row.FindControl("QuantityTextBox"); if (productNameLabel != null && quantityTextBox != null) { // Get the product name from the ProductNameLabel control. string name = productNameLabel.Text; // Get the quantity from the QuantityTextBox control. string quantity = quantityTextBox.Text; // Create the text to display in the ListBox control. string description = name + " - " + quantity + " Qty"; // Create a ListItem object using the description and // product name. ListItem item = new ListItem(description, name); // Add the ListItem object to the ListBox. ProductListBox.Items.Add(item); // Use the CommandSource property to retrieve // the Add button. Disable the button after // the user adds the currently displayed employee // name to the ListBox control. Button addButton = (Button)e.CommandSource; addButton.Enabled = false; } } } void ProductFormView_DataBound(Object sender, EventArgs e) { // To prevent the user from adding duplicate items, // disable the Add button if the item being bound to the // FormView control is already in the ListBox control. // Use the Row property to retrieve the data row. FormViewRow row = ProductFormView.Row; // Retrieve the Add button from the data row. Button addButton = (Button)row.FindControl("AddButton"); // Retrieve the ProductNameLabel control from // data row. Label productNameLabel = (Label)row.FindControl("ProductNameLabel"); if (addButton != null && productNameLabel != null) { // Get the product name from the ProductNameLabel // control. string name = productNameLabel.Text; // Use the FindByValue method to determine whether // the ListBox control already contains an entry for // the item. ListItem item = ProductListBox.Items.FindByValue(name); // Disable the Add button if the ListBox control // already contains the item. if (item != null) { addButton.Enabled = false; } else { addButton.Enabled = true; } } } </script> <html> <body> <form runat="server"> <h3>FormViewCommandEventArgs Example</h3> <asp:formview id="ProductFormView" datasourceid="ProductSource" allowpaging="true" datakeynames="ProductID" onitemcommand="ProductFormView_ItemCommand" ondatabound="ProductFormView_DataBound" runat="server"> <itemtemplate> <table> <tr> <td width="400px"> <b>Description:</b> <asp:label id="ProductNameLabel" text='<%# Eval("ProductName") %>' runat='server'/> <br/> <b>Price:</b> <asp:label id="PriceLabel" text='<%# Eval("UnitPrice", "{0:c}") %>' runat='server'/> <br/> <asp:textbox id="QuantityTextBox" width="50px" maxlength="3" runat="server"/> Qty </td> </tr> <tr> <td> <asp:requiredfieldvalidator ID="QuantityRequiredValidator" controltovalidate="QuantityTextBox" text="Please enter a quantity." display="Static" runat="server"/> <br/> <asp:CompareValidator id="QuantityCompareValidator" controltovalidate="QuantityTextBox" text="Please enter an integer value." display="Static" type="Integer" operator="DataTypeCheck" runat="server"/> </td> </tr> <tr> <td colspan="2"> <asp:button id="AddButton" text="Add" commandname="Add" runat="server"/> </td> </tr> </table> </itemtemplate> </asp:formview> <br/><br/><hr/> Items:<br/> <asp:listbox id="ProductListBox" 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="ProductSource" selectcommand="Select [ProductID], [ProductName], [UnitPrice] From [Products]" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>


System.EventArgs
System.Web.UI.WebControls.CommandEventArgs
System.Web.UI.WebControls.FormViewCommandEventArgs


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


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

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

このコンストラクタを使用して、FormViewCommandEventArgs クラスの新しいインスタンスを初期化します。
FormViewCommandEventArgs のインスタンスの初期プロパティ値を次の表に示します。
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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


FormViewCommandEventArgs プロパティ

名前 | 説明 | |
---|---|---|
![]() | CommandArgument | コマンドの引数を取得します。 ( CommandEventArgs から継承されます。) |
![]() | CommandName | コマンド名を取得します。 ( CommandEventArgs から継承されます。) |
![]() | CommandSource | イベントを発生させたコントロールを取得します。 |

FormViewCommandEventArgs メソッド

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

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

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


名前 | 説明 | |
---|---|---|
![]() | 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に収録されているすべての辞書からFormViewCommandEventArgsを検索する場合は、下記のリンクをクリックしてください。

- FormViewCommandEventArgsのページへのリンク