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

DetailsViewCommandEventArgs クラス

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

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

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

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

ButtonField、CommandField、または TemplateField 行フィールド内のボタンがクリックされると、DetailsView コントロールが ItemCommand イベントを発生させます。これにより、このイベントが発生するたびにカスタム ルーチンを実行するイベント ハンドラを提供できます。

メモメモ

また、DetailsView コントロールは、特定のボタン (CommandName プロパティが "Delete"、"Insert"、"Page"、または "Update" に設定されているボタン) がクリックされた場合、その他の特別なイベントを発生させます。これらのボタンを使用する場合は、コントロールから提供される特別なイベントのいずれか (ItemDeleted や ItemDeleting など) の使用を考慮する必要があります。

DetailsViewCommandEventArgs オブジェクトはイベント ハンドラに渡されます。イベントを発生させたボタンにコマンド名またはコマンド引数が指定されている場合は、DetailsViewCommandEventArgs オブジェクトを使用して、それらの値を確認できます。クリックされたボタンのコマンド名を確認するには CommandName プロパティを、コマンド引数を確認するには CommandArgument プロパティを使用します。また、CommandSource プロパティを使用して、イベントを発生させた DetailsView コントロールにアクセスすることもできます。

DetailsViewCommandEventArgs クラスのインスタンスの初期プロパティ値の一覧については、DetailsViewCommandEventArgs コンストラクタのトピックを参照してください。

使用例使用例

ItemCommand イベントのイベント ハンドラに渡される DetailsViewCommandEventArgs オブジェクトを使用して、ユーザーがクリックしたボタンのコマンド名を確認する方法のコード例を次に示します。この例ではシングル ファイルのコーディング モデルを使用します。

<%@ page language="VB" autoeventwireup="false"
 %>

<script runat="server">
  
  Sub ItemDetailsView_ItemCommand(ByVal sender
 As Object, _
    ByVal e As DetailsViewCommandEventArgs)
 _
    Handles ItemDetailsView.ItemCommand

    ' Use the CommandName property to determine which button
    ' was clicked. 
    If e.CommandName = "Add" Then

      ' Add the customer to the customer list. 

      ' Get the row that contains the company name. In this
      ' example, the company name is in the second row (index 1)  
      ' of the DetailsView control.
      Dim row As DetailsViewRow = ItemDetailsView.Rows(1)

      ' Get the company's name from the appropriate cell.
      ' In this example, the company name is in the second cell  
      ' (index 1) of the row.
      Dim name As String
 = row.Cells(1).Text

      ' Create a ListItem object with the company name.
      Dim item As New ListItem(name)

      ' Add the ListItem object to the ListBox control, if the 
      ' item does not already exist.
      If Not CustomerListBox.Items.Contains(item)
 Then

        CustomerListBox.Items.Add(item)
        
      End If

    End If

  End Sub
  
</script>

<html>
  <body>
    <form runat="server">
    
      <h3>DetailsViewCommandEventArgs Example</h3>
  
      <asp:detailsview id="ItemDetailsView"
        datasourceid="DetailsViewSource"
        allowpaging="true"
        autogeneraterows="false"  
        runat="server">
        <fields>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID"/>
          <asp:boundfield datafield="CompanyName"
            headertext="Company Name"/>
          <asp:boundfield datafield="Address"
            headertext="Address"/>
          <asp:boundfield datafield="City"
            headertext="City"/>
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"
            headertext="Country"/>
          <asp:buttonfield buttontype="Link"
            causesvalidation="false"
            text="Add to List"
            commandname="Add"/>
        </fields>
      </asp:detailsview>
      
      <br/><br/>
      
      Selected Customers:<br/>
      <asp:listbox id="CustomerListBox"
        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="DetailsViewSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], 
          [City], [PostalCode], [Country] From [Customers]"
        connectionstring=
            "<%$ ConnectionStrings:NorthWindConnectionString%>"
 
        runat="server"/>  
  
    </form>
  </body>
</html>
<%@ page language="C#" %>

<script runat="server">
  
  void ItemDetailsView_ItemCommand(Object sender, 
      DetailsViewCommandEventArgs e)
  {

    // Use the CommandName property to determine which button
    // was clicked. 
    if (e.CommandName == "Add")
    {

      // Add the customer to the customer list. 

      // Get the row that contains the company name. In this
      // example, the company name is in the second row (index 1)  
      // of the DetailsView control.
      DetailsViewRow row = ItemDetailsView.Rows[1];

      // Get the company's name from the appropriate cell.
      // In this example, the company name is in the second cell  
      // (index 1) of the row.
      String name = row.Cells[1].Text;

      // Create a ListItem object with the company name.
      ListItem item = new ListItem(name);

      // Add the ListItem object to the ListBox control, if the 
      // item does not already exist.
      if (!CustomerListBox.Items.Contains(item))
      {
        CustomerListBox.Items.Add(item);
      }

    }

  }
  
</script>

<html>
  <body>
    <form runat="server">
    
      <h3>DetailsViewCommandEventArgs Example</h3>
  
      <asp:detailsview id="ItemDetailsView"
        datasourceid="DetailsViewSource"
        allowpaging="true"
        autogeneraterows="false" 
        onitemcommand="ItemDetailsView_ItemCommand"  
        runat="server">
        <fields>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID"/>
          <asp:boundfield datafield="CompanyName"
            headertext="Company Name"/>
          <asp:boundfield datafield="Address"
            headertext="Address"/>
          <asp:boundfield datafield="City"
            headertext="City"/>
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"
            headertext="Country"/>
          <asp:buttonfield buttontype="Link"
            causesvalidation="false"
            text="Add to List"
            commandname="Add"/>
        </fields>
      </asp:detailsview>
      
      <br/><br/>
      
      Selected Customers:<br/>
      <asp:listbox id="CustomerListBox"
        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="DetailsViewSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], 
          [City], [PostalCode], [Country] From [Customers]"
        connectionstring=
            "<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>  
  
    </form>
  </body>
</html>

前の例の分離コード コーディング モデルを次のコード例に示します。この例を正常に動作させるには、以下のコードを関連付けられた分離コード ファイルにコピーする必要があります。

<%@ Page Language="VB" AutoEventWireup="false"
 CodeFile="DefaultVB.aspx.vb" Inherits="DefaultVB"
 %>

<html>
  <body>
    <form id="Form1" runat="server">
    
      <h3>DetailsViewCommandEventArgs Example</h3>
  
      <asp:detailsview id="ItemDetailsView"
        datasourceid="DetailsViewSource"
        allowpaging="true"
        autogeneraterows="false" 
        onitemcommand="ItemDetailsView_ItemCommand"
  
        runat="server">
        <fields>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID"/>
          <asp:boundfield datafield="CompanyName"
            headertext="Company Name"/>
          <asp:boundfield datafield="Address"
            headertext="Address"/>
          <asp:boundfield datafield="City"
            headertext="City"/>
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"
            headertext="Country"/>
          <asp:buttonfield buttontype="Link"
            causesvalidation="false"
            text="Add to List"
            commandname="Add"/>
        </fields>
      </asp:detailsview>
      
      <br/><br/>
      
      Selected Customers:<br/>
      <asp:listbox id="CustomerListBox"
        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="DetailsViewSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], 
          [City], [PostalCode], [Country] From [Customers]"
        connectionstring=
          "<%$ ConnectionStrings:NorthWindConnectionString%>"
 
        runat="server"/>  
  
    </form>
  </body>
</html>
<%@ Page Language="C#" AutoEventWireup="true"
 CodeFile="Default.aspx.cs" Inherits="_Default" %>

<html>
  <body>
    <form id="Form1" runat="server">
    
      <h3>DetailsViewCommandEventArgs Example</h3>
  
      <asp:detailsview id="ItemDetailsView"
        datasourceid="DetailsViewSource"
        allowpaging="true"
        autogeneraterows="false" 
        onitemcommand="ItemDetailsView_ItemCommand"  
        runat="server">
        <fields>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID"/>
          <asp:boundfield datafield="CompanyName"
            headertext="Company Name"/>
          <asp:boundfield datafield="Address"
            headertext="Address"/>
          <asp:boundfield datafield="City"
            headertext="City"/>
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"
            headertext="Country"/>
          <asp:buttonfield buttontype="Link"
            causesvalidation="false"
            text="Add to List"
            commandname="Add"/>
        </fields>
      </asp:detailsview>
      
      <br/><br/>
      
      Selected Customers:<br/>
      <asp:listbox id="CustomerListBox"
        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="DetailsViewSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City],
 [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
 
        runat="server"/>  
  
    </form>
  </body>
</html>

前の例の分離コード ファイルのコード例を次に示します。

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    public void ItemDetailsView_ItemCommand(Object
 sender, DetailsViewCommandEventArgs e)
    {

        // Use the CommandName property to determine which button
        // was clicked. 
        if (e.CommandName == "Add")
        {

            // Add the customer to the customer list. 

            // Get the row that contains the company name. In this
            // example, the company name is in the second row (index
 1)  
            // of the DetailsView control.
            DetailsViewRow row = ItemDetailsView.Rows[1];

            // Get the company's name from the appropriate cell.
            // In this example, the company name is in the second cell
  
            // (index 1) of the row.
            String name = row.Cells[1].Text;

            // Create a ListItem object with the company name.
            ListItem item = new ListItem(name);

            // Add the ListItem object to the ListBox control, if the
 
            // item does not already exist.
            if (!CustomerListBox.Items.Contains(item))
            {
                CustomerListBox.Items.Add(item);
            }

        }

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

DetailsViewCommandEventArgs コンストラクタ

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

DetailsViewCommandEventArgs クラスの新しいインスタンスを初期化します。

名前空間: 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 DetailsViewCommandEventArgs(commandSource,
 originalArgs)
public DetailsViewCommandEventArgs (
    Object commandSource,
    CommandEventArgs originalArgs
)
public:
DetailsViewCommandEventArgs (
    Object^ commandSource, 
    CommandEventArgs^ originalArgs
)
public DetailsViewCommandEventArgs (
    Object commandSource, 
    CommandEventArgs originalArgs
)
public function DetailsViewCommandEventArgs
 (
    commandSource : Object, 
    originalArgs : CommandEventArgs
)

パラメータ

commandSource

コマンドのソース。

originalArgs

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

解説解説

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

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

プロパティ

初期値

CommandArgument

originalArgs パラメータに格納された CommandEventArgs の CommandArgument プロパティ値。

CommandName

originalArgs パラメータに格納された CommandEventArgs オブジェクトの CommandName プロパティ値。

CommandSource

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

メモメモ

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

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

DetailsViewCommandEventArgs プロパティ


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

  名前 説明
パブリック プロパティ CommandArgument  コマンドの引数を取得します。 ( CommandEventArgs から継承されます。)
パブリック プロパティ CommandName  コマンド名を取得します。 ( CommandEventArgs から継承されます。)
パブリック プロパティ CommandSource コマンドのソースを取得します。
参照参照

関連項目

DetailsViewCommandEventArgs クラス
System.Web.UI.WebControls 名前空間
DetailsView クラス
DetailsViewCommandEventHandler
ButtonField クラス
TemplateField
CommandEventArgs クラス
DetailsView.ItemCommand イベント
OnItemCommand

DetailsViewCommandEventArgs メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

DetailsViewCommandEventArgs クラス
System.Web.UI.WebControls 名前空間
DetailsView クラス
DetailsViewCommandEventHandler
ButtonField クラス
TemplateField
CommandEventArgs クラス
DetailsView.ItemCommand イベント
OnItemCommand

DetailsViewCommandEventArgs メンバ

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

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


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

関連項目

DetailsViewCommandEventArgs クラス
System.Web.UI.WebControls 名前空間
DetailsView クラス
DetailsViewCommandEventHandler
ButtonField クラス
TemplateField
CommandEventArgs クラス
DetailsView.ItemCommand イベント
OnItemCommand



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「DetailsViewCommandEventArgs」の関連用語

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

   

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



DetailsViewCommandEventArgsのページの著作権

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

©2026 GRAS Group, Inc.RSS