DetailsView.ItemCommand イベントとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DetailsView.ItemCommand イベントの意味・解説 

DetailsView.ItemCommand イベント

メモ : このイベントは、.NET Framework version 2.0新しく追加されたものです。

DetailsView コントロール内のボタンクリックされた場合発生します

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

Public Event ItemCommand As
 DetailsViewCommandEventHandler
Dim instance As DetailsView
Dim handler As DetailsViewCommandEventHandler

AddHandler instance.ItemCommand, handler
public event DetailsViewCommandEventHandler ItemCommand
public:
event DetailsViewCommandEventHandler^ ItemCommand {
    void add (DetailsViewCommandEventHandler^ value);
    void remove (DetailsViewCommandEventHandler^ value);
}
/** @event */
public void add_ItemCommand (DetailsViewCommandEventHandler
 value)

/** @event */
public void remove_ItemCommand (DetailsViewCommandEventHandler
 value)
JScript では、イベント使用できますが、新規に宣言することはできません。
解説解説
使用例使用例

ItemCommand イベント使用してDetailsView コントロールボタン クリック処理する方法コード例次に示しますユーザーAdd Contact ボタンクリックすると、項目が ListBox コントロール追加されます。

<%@ Page Language="VB" %>

<script runat="server">

  Sub CustomerDetailView_ItemCommand(ByVal
 sender As Object, ByVal
 e As DetailsViewCommandEventArgs)
    
        ' Use the CommandName property to determine which button
        ' was clicked. 
        If e.CommandName = "Add"
 Then

            ' Add the current store to the contact list. 
     
            ' Get the row that contains the store name. In this
            ' example, the store name is in the second row (index 1)
  
            ' of the DetailsView control.
            Dim row As DetailsViewRow = CustomerDetailView.Rows(1)
      
            ' Get the store's name from the appropriate cell.
            ' In this example, the store 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 store's name.
            Dim item As New
 ListItem(name)

            ' Add the ListItem object to the ListBox, if the 
            ' item doesn't already exist.
            If Not ContactListBox.Items.Contains(item)
 Then
      
                ContactListBox.Items.Add(item)
      
            End If
        
        End If
    
    End Sub

</script>

<html>
<body>
    <form id="Form1" runat="server">
        <h3>
            DetailsView ItemCommand Example</h3>
        <asp:DetailsView ID="CustomerDetailView"
 
            DataSourceID="DetailsViewSource"
            AutoGenerateRows="false" 
            DataKeyNames="CustomerID" 
            AllowPaging="true" 
            OnItemCommand="CustomerDetailView_ItemCommand"
            runat="server">
            
            <FieldHeaderStyle BackColor="Navy"
 ForeColor="White" />
            
            <Fields>
                <asp:BoundField DataField="CustomerID"
 HeaderText="Store ID" />
                <asp:BoundField DataField="CompanyName"
 HeaderText="Store Name" />
                <asp:BoundField DataField="City"
 HeaderText="City" />
                <asp:ButtonField CommandName="Add"
 Text="Add Contact" />
            </Fields>
        </asp:DetailsView>
        
        <hr />
        
        Contacts:<br />
        <asp:ListBox ID="ContactListBox" 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"
 runat="server" 
          ConnectionString=
            "<%$ ConnectionStrings:NorthWindConnectionString%>"
            InsertCommand="INSERT INTO [Customers]([CustomerID],
 [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID,
 @CompanyName, @Address, @City, @PostalCode, @Country)"
          SelectCommand="Select [CustomerID], [CompanyName], 
            [Address], [City], [PostalCode], [Country] From 
            [Customers]">
        </asp:SqlDataSource>
    </form>
</body>
</html>
<%@ Page Language="C#" %>

<script runat="server">

    void CustomerDetailView_ItemCommand(Object sender, DetailsViewCommandEventArgs
 e)
    {

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

            // Add the current store to the contact list. 

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

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

            // Create a ListItem object with the store's name.
            ListItem item = new ListItem(name);

            // Add the ListItem object to the ListBox, if the 
            // item doesn't already exist.
            if (!ContactListBox.Items.Contains(item))
            {
                ContactListBox.Items.Add(item);
            }

        }

    }

</script>

<html>
<body>
    <form id="Form1" runat="server">
        <h3>
            DetailsView ItemCommand Example</h3>
        <asp:DetailsView ID="CustomerDetailView" 
            DataSourceID="DetailsViewSource"
            AutoGenerateRows="false" 
            DataKeyNames="CustomerID" 
            AllowPaging="true" 
            OnItemCommand="CustomerDetailView_ItemCommand"
            runat="server">
            
            <FieldHeaderStyle BackColor="Navy" ForeColor="White"
 />
            
            <Fields>
                <asp:BoundField DataField="CustomerID" HeaderText="Store
 ID" />
                <asp:BoundField DataField="CompanyName" HeaderText="Store
 Name" />
                <asp:BoundField DataField="City" HeaderText="City"
 />
                <asp:ButtonField CommandName="Add" Text="Add Contact"
 />
            </Fields>
        </asp:DetailsView>
        
        <hr />
        
        Contacts:<br />
        <asp:ListBox ID="ContactListBox" 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" runat="server"
 
          ConnectionString=
            "<%$ ConnectionStrings:NorthWindConnectionString%>"
            InsertCommand="INSERT INTO [Customers]([CustomerID], [CompanyName],
 [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName,
 @Address, @City, @PostalCode, @Country)"
          SelectCommand="Select [CustomerID], [CompanyName], 
            [Address], [City], [PostalCode], [Country] From 
            [Customers]">
        </asp:SqlDataSource>
    </form>
</body>
</html>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DetailsView クラス
DetailsView メンバ
System.Web.UI.WebControls 名前空間
DetailsViewCommandEventArgs
DetailsView.PageIndex プロパティ
CommandEventArgs.CommandName プロパティ
CommandEventArgs.CommandArgument プロパティ
OnItemCommand
その他の技術情報
イベント利用


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

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

辞書ショートカット

すべての辞書の索引

「DetailsView.ItemCommand イベント」の関連用語

DetailsView.ItemCommand イベントのお隣キーワード
検索ランキング

   

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



DetailsView.ItemCommand イベントのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS