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

GridViewCommandEventArgs クラス

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

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

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

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

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

メモメモ

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

GridViewCommandEventArgs オブジェクトイベント処理メソッド渡されることにより、クリックされたボタンコマンド名およびコマンド引数確認できますコマンド名を確認するには CommandName プロパティを、コマンド引数確認するには CommandArgument プロパティ使用します。CommandSource プロパティ使用してイベント発生させたボタン コントロールアクセスすることもできます

イベント処理詳細については、「イベント利用」を参照してください

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

使用例使用例

イベント処理メソッド渡されGridViewCommandEventArgs オブジェクト使用してイベント発生させたボタンコマンド名を確認する方法次の例に示します

<%@ Page language="VB" %>

<script runat="server">

  Sub CustomersGridView_RowCommand(ByVal sender
 As Object, ByVal e As
 GridViewCommandEventArgs)

    ' If multiple buttons are used in a GridView control, use the
    ' CommandName property to determine which button was clicked.
    If e.CommandName = "Add" Then
    
      ' Convert the row index stored in the CommandArgument
      ' property to an Integer.
      Dim index As Integer
 = Convert.ToInt32(e.CommandArgument)
            
      ' Retrieve the row that contains the button clicked 
      ' by the user from the Rows collection.
      Dim row As GridViewRow = CustomersGridView.Rows(index)
            
      ' Create a new ListItem object for the customer in the row.  
   
      Dim item As New ListItem()
      item.Text = Server.HtmlDecode(row.Cells(2).Text)
            
      ' If the customer is not already in the ListBox, add the ListItem
 
      ' object to the Items collection of the ListBox control. 
      If Not CustomersListBox.Items.Contains(item)
 Then
      
        CustomersListBox.Items.Add(item)
        
      End If
      
    End If
    
  End Sub

  Sub CustomersGridView_RowCreated(ByVal sender
 As Object, ByVal e As
 GridViewRowEventArgs)
    
    ' The GridViewCommandEventArgs class does not contain a 
    ' property that indicates which row's command button was
    ' clicked. To identify which row's button was clicked, use 
    ' the button's CommandArgument property by setting it to the 
    ' row's index.
    If e.Row.RowType = DataControlRowType.DataRow Then
    
      ' Retrieve the LinkButton control from the first column.
      Dim addButton As LinkButton = CType(e.Row.Cells(0).Controls(0),
 LinkButton)
          
      ' Set the LinkButton's CommandArgument property with the
      ' row's index.
      addButton.CommandArgument = e.Row.RowIndex.ToString()
      
    End If

  End Sub
    
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridView RowCommand Example</h3>
            
      <table width="100%">         
        <tr>                
          <td width="50%">
                    
            <asp:gridview id="CustomersGridView"
 
              datasourceid="CustomersSource"
              allowpaging="true" 
              autogeneratecolumns="false"
              onrowcommand="CustomersGridView_RowCommand"
              onrowcreated="CustomersGridView_RowCreated"
  
              runat="server">
                
              <columns>
                <asp:buttonfield buttontype="Link"
 
                  commandname="Add" 
                  text="Add"/>
                <asp:boundfield datafield="CustomerID"
 
                  headertext="Customer ID"/>
                <asp:boundfield datafield="CompanyName"
 
                  headertext="Company Name"/> 
                <asp:boundfield datafield="City"
 
                  headertext="City"/>         
              </columns>
                
            </asp:gridview>
                    
          </td>
                    
          <td valign="top" width="50%">
                    
            Customers: <br/>
            <asp:listbox id="CustomersListBox"
              runat="server"/> 
                    
          </td>  
        </tr>      
      </table>
            
      <!-- 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="CustomersSource"
        selectcommand="Select [CustomerID], [CompanyName], [City]
 From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
 
        runat="server"/>
            
    </form>
  </body>
</html>

<%@ Page language="C#" %>

<script runat="server">

  void CustomersGridView_RowCommand(Object sender, GridViewCommandEventArgs
 e)
  {
    // If multiple buttons are used in a GridView control, use the
    // CommandName property to determine which button was clicked.
    if(e.CommandName=="Add")
    {
      // Convert the row index stored in the CommandArgument
      // property to an Integer.
      int index = Convert.ToInt32(e.CommandArgument);
            
      // Retrieve the row that contains the button clicked 
      // by the user from the Rows collection.
      GridViewRow row = CustomersGridView.Rows[index];
            
      // Create a new ListItem object for the customer in the row. 
    
      ListItem item = new ListItem();
      item.Text = Server.HtmlDecode(row.Cells[2].Text);
            
      // If the customer is not already in the ListBox, add the ListItem
 
      // object to the Items collection of the ListBox control. 
      if (!CustomersListBox.Items.Contains(item))
      {
        CustomersListBox.Items.Add(item);
      }           
    }
  }

  void CustomersGridView_RowCreated(Object sender, GridViewRowEventArgs
 e)
  {
    
    // The GridViewCommandEventArgs class does not contain a 
    // property that indicates which row's command button was
    // clicked. To identify which row's button was clicked, use 
    // the button's CommandArgument property by setting it to the 
    // row's index.
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
      // Retrieve the LinkButton control from the first column.
      LinkButton addButton = (LinkButton)e.Row.Cells[0].Controls[0];
          
      // Set the LinkButton's CommandArgument property with the
      // row's index.
      addButton.CommandArgument = e.Row.RowIndex.ToString();
    }

  }
    
</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridView RowCommand Example</h3>
            
      <table width="100%">         
        <tr>                
          <td width="50%">
                    
            <asp:gridview id="CustomersGridView" 
              datasourceid="CustomersSource"
              allowpaging="true" 
              autogeneratecolumns="false"
              onrowcommand="CustomersGridView_RowCommand"
              onrowcreated="CustomersGridView_RowCreated"  
              runat="server">
                
              <columns>
                <asp:buttonfield buttontype="Link" 
                  commandname="Add" 
                  text="Add"/>
                <asp:boundfield datafield="CustomerID" 
                  headertext="Customer ID"/>
                <asp:boundfield datafield="CompanyName" 
                  headertext="Company Name"/> 
                <asp:boundfield datafield="City" 
                  headertext="City"/>         
              </columns>
                
            </asp:gridview>
                    
          </td>
                    
          <td valign="top" width="50%">
                    
            Customers: <br/>
            <asp:listbox id="CustomersListBox"
              runat="server"/> 
                    
          </td>  
        </tr>      
      </table>
            
      <!-- 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="CustomersSource"
        selectcommand="Select [CustomerID], [CompanyName], [City] From [Customers]"
        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.GridViewCommandEventArgs
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
GridViewCommandEventArgs メンバ
System.Web.UI.WebControls 名前空間
GridView クラス
GridViewCommandEventHandler
ButtonField クラス
TemplateField
CommandEventArgs クラス
CommandEventArgs.CommandArgument プロパティ
GridView.RowCommand イベント
その他の技術情報
イベント利用

GridViewCommandEventArgs コンストラクタ (GridViewRow, Object, CommandEventArgs)

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

行、コマンドソース、およびイベント引数指定して、GridViewCommandEventArgs クラス新しインスタンス初期化します。

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

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

Dim instance As New GridViewCommandEventArgs(row,
 commandSource, originalArgs)
public GridViewCommandEventArgs (
    GridViewRow row,
    Object commandSource,
    CommandEventArgs originalArgs
)
public:
GridViewCommandEventArgs (
    GridViewRow^ row, 
    Object^ commandSource, 
    CommandEventArgs^ originalArgs
)
public GridViewCommandEventArgs (
    GridViewRow row, 
    Object commandSource, 
    CommandEventArgs originalArgs
)
public function GridViewCommandEventArgs (
    row : GridViewRow, 
    commandSource : Object, 
    originalArgs : CommandEventArgs
)

パラメータ

row

ボタン含んだ行を表す GridViewRow オブジェクト

commandSource

コマンドソース

originalArgs

イベント データ格納された CommandEventArgs オブジェクト

解説解説

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

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

プロパティ

初期値

CommandArgument

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

CommandName

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

CommandSource

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

メモメモ

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

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

GridViewCommandEventArgs コンストラクタ

GridViewCommandEventArgs クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
GridViewCommandEventArgs (Object, CommandEventArgs) コマンドソースイベント引数指定してGridViewCommandEventArgs クラス新しインスタンス初期化します。
GridViewCommandEventArgs (GridViewRow, Object, CommandEventArgs) 行、コマンドソース、およびイベント引数指定してGridViewCommandEventArgs クラス新しインスタンス初期化します。
参照参照

関連項目

GridViewCommandEventArgs クラス
GridViewCommandEventArgs メンバ
System.Web.UI.WebControls 名前空間
CommandEventArgs クラス
CommandEventArgs.CommandArgument プロパティ
CommandEventArgs.CommandName プロパティ
CommandSource

GridViewCommandEventArgs コンストラクタ (Object, CommandEventArgs)

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

コマンドソースイベント引数指定して、GridViewCommandEventArgs クラス新しインスタンス初期化します。

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

パラメータ

commandSource

コマンドソース

originalArgs

イベント データ格納された CommandEventArgs オブジェクト

解説解説

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

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

プロパティ

初期値

CommandArgument

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

CommandName

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

CommandSource

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

メモメモ

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

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

GridViewCommandEventArgs プロパティ


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

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

関連項目

GridViewCommandEventArgs クラス
System.Web.UI.WebControls 名前空間
GridView クラス
GridViewCommandEventHandler
ButtonField クラス
TemplateField
CommandEventArgs クラス
CommandEventArgs.CommandArgument プロパティ
GridView.RowCommand イベント

その他の技術情報

イベント利用

GridViewCommandEventArgs メソッド


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

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

関連項目

GridViewCommandEventArgs クラス
System.Web.UI.WebControls 名前空間
GridView クラス
GridViewCommandEventHandler
ButtonField クラス
TemplateField
CommandEventArgs クラス
CommandEventArgs.CommandArgument プロパティ
GridView.RowCommand イベント

その他の技術情報

イベント利用

GridViewCommandEventArgs メンバ

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

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


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

関連項目

GridViewCommandEventArgs クラス
System.Web.UI.WebControls 名前空間
GridView クラス
GridViewCommandEventHandler
ButtonField クラス
TemplateField
CommandEventArgs クラス
CommandEventArgs.CommandArgument プロパティ
GridView.RowCommand イベント

その他の技術情報

イベント利用



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

辞書ショートカット

すべての辞書の索引

「GridViewCommandEventArgs」の関連用語

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

   

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



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

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

©2024 GRAS Group, Inc.RSS