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 パラメータ格納されCommandEventArgsCommandArgument プロパティ値。

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



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

辞書ショートカット

すべての辞書の索引

「DetailsViewCommandEventArgs」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS