FormViewCommandEventArgsとは? わかりやすく解説

FormViewCommandEventArgs クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

ItemCommand イベントデータ提供します

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Class FormViewCommandEventArgs
    Inherits CommandEventArgs
Dim instance As FormViewCommandEventArgs
public class FormViewCommandEventArgs : CommandEventArgs
public ref class FormViewCommandEventArgs :
 public CommandEventArgs
public class FormViewCommandEventArgs extends
 CommandEventArgs
public class FormViewCommandEventArgs extends
 CommandEventArgs
解説解説

ItemCommand イベントは、FormView コントロール内のボタン コントロールクリックされた場合発生します。これにより、このイベント発生するたびにカスタム ルーチン実行するイベント処理メソッドを提供できます

FormView コントロール内のボタンから、コントロール組み込み機能一部呼び出すこともできます。これらのいずれか操作実行するには、ボタンCommandName プロパティ次の表の値のいずれかに設定します

前述の表に示されているボタンクリックされると 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>

.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.EventArgs
     System.Web.UI.WebControls.CommandEventArgs
      System.Web.UI.WebControls.FormViewCommandEventArgs
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
FormViewCommandEventArgs メンバ
System.Web.UI.WebControls 名前空間
FormView クラス
FormViewCommandEventHandler
CommandEventArgs クラス
FormView.ItemCommand イベント
OnItemCommand

FormViewCommandEventArgs コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

FormViewCommandEventArgs クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Sub New ( _
    commandSource As Object, _
    originalArgs As CommandEventArgs _
)
Dim commandSource As Object
Dim originalArgs As CommandEventArgs

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

パラメータ

commandSource

コマンドソース

originalArgs

イベント データ格納している CommandEventArgs。

解説解説

このコンストラクタ使用してFormViewCommandEventArgs クラス新しインスタンス初期化します。

FormViewCommandEventArgsインスタンス初期プロパティ値を次の表に示します

プロパティ

初期値

CommandArgument

originalArgs パラメータ格納されCommandEventArgsCommandArgument プロパティの値。

CommandName

originalArgs パラメータ格納されCommandEventArgsCommandName プロパティの値。

CommandSource

commandSource パラメータ格納されオブジェクト

メモメモ

このコンストラクタは、主にコントロール開発者イベント発生させる場合使用します

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
FormViewCommandEventArgs クラス
FormViewCommandEventArgs メンバ
System.Web.UI.WebControls 名前空間
CommandEventArgs クラス
CommandEventArgs.CommandArgument プロパティ
CommandEventArgs.CommandName プロパティ
CommandSource
OnItemCommand

FormViewCommandEventArgs プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ CommandArgument  コマンド引数取得します。 ( CommandEventArgs から継承されます。)
パブリック プロパティ CommandName  コマンド名を取得します。 ( CommandEventArgs から継承されます。)
パブリック プロパティ CommandSource イベント発生させたコントロール取得します
参照参照

関連項目

FormViewCommandEventArgs クラス
System.Web.UI.WebControls 名前空間
FormView クラス
FormViewCommandEventHandler
CommandEventArgs クラス
FormView.ItemCommand イベント
OnItemCommand

FormViewCommandEventArgs メソッド


FormViewCommandEventArgs メンバ

ItemCommand イベントデータ提供します

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


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド FormViewCommandEventArgs FormViewCommandEventArgs クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ CommandArgument  コマンド引数取得します。(CommandEventArgs から継承されます。)
パブリック プロパティ CommandName  コマンド名を取得します。(CommandEventArgs から継承されます。)
パブリック プロパティ CommandSource イベント発生させたコントロール取得します
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

FormViewCommandEventArgs クラス
System.Web.UI.WebControls 名前空間
FormView クラス
FormViewCommandEventHandler
CommandEventArgs クラス
FormView.ItemCommand イベント
OnItemCommand


このページでは「.NET Framework クラス ライブラリ リファレンス」からFormViewCommandEventArgsを検索した結果を表示しています。
Weblioに収録されているすべての辞書からFormViewCommandEventArgsを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からFormViewCommandEventArgs を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「FormViewCommandEventArgs」の関連用語

FormViewCommandEventArgsのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



FormViewCommandEventArgsのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS