GridViewRowEventHandler デリゲートとは? わかりやすく解説

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

GridViewRowEventHandler デリゲート

メモ : このデリゲートは、.NET Framework version 2.0 で新しく追加されたものです。

GridView コントロールの RowCreated イベントと RowDataBound イベントを処理するメソッドを表します。

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

Public Delegate Sub GridViewRowEventHandler
 ( _
    sender As Object, _
    e As GridViewRowEventArgs _
)
Dim instance As New GridViewRowEventHandler(AddressOf
 HandlerMethod)
public delegate void GridViewRowEventHandler
 (
    Object sender,
    GridViewRowEventArgs e
)
public delegate void GridViewRowEventHandler
 (
    Object^ sender, 
    GridViewRowEventArgs^ e
)
/** @delegate */
public delegate void GridViewRowEventHandler
 (
    Object sender, 
    GridViewRowEventArgs e
)
JScript では、デリゲートは使用できますが、新規に宣言することはできません。

パラメータ

sender

イベントのソース。

e

イベント データを格納している GridViewRowEventArgs オブジェクト。

解説解説

GridView コントロールの表示前に、コントロールの各行の GridViewRow オブジェクトを作成する必要があります。RowCreated イベントは、GridView コントロールに行が作成されるたびに発生します。これにより、このイベントが発生するたびにカスタム ルーチン (行へのカスタム コンテンツの追加など) を実行するイベント処理メソッドを提供できます。

同様に、コントロールの各行は、GridView コントロールの表示前にデータ ソースのレコードにバインドする必要があります。RowDataBound イベントは、(GridViewRow オブジェクトによって表される) データ行が GridView コントロールのデータにバインドされたときに発生します。これにより、このイベントが発生するたびにカスタム ルーチン (行にバインドされたデータの値を変更するなど) を実行するイベント処理メソッドを提供できます。

GridViewRowEventHandler デリゲートを作成する場合は、イベントを処理するメソッドを識別してください。イベントをイベント ハンドラに関連付けるには、デリゲートのインスタンスをイベントに追加します。デリゲートを削除しない限り、そのイベントが発生すると常にイベント ハンドラが呼び出されます。イベント ハンドラ デリゲートの詳細については、「イベントとデリゲート」を参照してください。

使用例使用例

GridViewRowEventHandler デリゲートを、プログラムによって GridView コントロールの RowDataBound イベントに追加する方法を次の例に示します。

<%@ Page language="VB" %>

<script runat="server">

  Sub Page_Load(ByVal sender As
 Object, ByVal e As EventArgs)
        
    ' Create a new GridView control.
    Dim customersGridView As New
 GridView()
         
    ' Set the GridView control's properties.
    customersGridView.ID = "CustomersGridView"
    customersGridView.DataSourceID = "CustomersSqlDataSource"
    customersGridView.AutoGenerateColumns = True
    customersGridView.AllowPaging = True

    ' Programmatically register the event-handling method.
    AddHandler customersGridView.RowDataBound, AddressOf
 CustomersGridView_RowDataBound
       
    ' Add the GridView control to the Controls collection
    ' of the PlaceHolder control.
    GridViewPlaceHolder.Controls.Add(customersGridView)

  End Sub

  Sub CustomersGridView_RowDataBound(ByVal
 sender As Object, ByVal
 e As GridViewRowEventArgs)
        
    If e.Row.RowType = DataControlRowType.DataRow Then
    
      ' Display the company name in italics.
      e.Row.Cells(1).Text = "<i>" & e.Row.Cells(1).Text
 & "</i>"
        
    End If
    
  End Sub

</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridViewRowEventHandler Example</h3>

      <asp:placeholder id="GridViewPlaceHolder"
        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="CustomersSqlDataSource"
  
        selectcommand="Select [CustomerID], [CompanyName], [Address],
 [City], [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
            
    </form>
  </body>
</html>

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

<script runat="server">

  void Page_Load(Object sender, EventArgs e)
  {
        
    // Create a new GridView control.
    GridView customersGridView = new GridView();
         
    // Set the GridView control's properties.
    customersGridView.ID = "CustomersGridView";
    customersGridView.DataSourceID = "CustomersSqlDataSource";
    customersGridView.AutoGenerateColumns = true;
    customersGridView.AllowPaging = true;

    // Programmatically register the event-handling method.
    customersGridView.RowDataBound += new GridViewRowEventHandler(this.CustomersGridView_RowDataBound);
       
    // Add the GridView control to the Controls collection
    // of the PlaceHolder control.
    GridViewPlaceHolder.Controls.Add(customersGridView);

  }

  void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs
 e)
  {
        
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
      // Display the company name in italics.
      e.Row.Cells[1].Text = "<i>" + e.Row.Cells[1].Text + "</i>";
        
    }
    
  }

</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridViewRowEventHandler Example</h3>

      <asp:placeholder id="GridViewPlaceHolder"
        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="CustomersSqlDataSource"  
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City],
 [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
            
    </form>
  </body>
</html>

GridViewRowEventHandler デリゲートを、宣言によって GridView コントロールの RowDataBound イベントに追加する方法を次の例に示します。

<%@ Page language="VB" %>

<script runat="server">

  Sub CustomersGridView_RowDataBound(ByVal
 sender As Object, ByVal
 e As GridViewRowEventArgs)

    If e.Row.RowType = DataControlRowType.DataRow Then
    
      ' Display the company name in italics.
      e.Row.Cells(1).Text = "<i>" & e.Row.Cells(1).Text
 & "</i>"
        
    End If
    
  End Sub

</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridView RowDataBound Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="true"
        allowpaging="true"
        onrowdatabound="CustomersGridView_RowDataBound"
 
        runat="server">
      </asp:gridview>
            
      <!-- 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="CustomersSqlDataSource"
  
        selectcommand="Select [CustomerID], [CompanyName], [Address],
 [City], [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
            
    </form>
  </body>
</html>

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

<script runat="server">

  void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs
 e)
  {
        
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
      // Display the company name in italics.
      e.Row.Cells[1].Text = "<i>" + e.Row.Cells[1].Text + "</i>";
        
    }
    
  }

</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridView RowDataBound Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="true"
        allowpaging="true"
        onrowdatabound="CustomersGridView_RowDataBound" 
        runat="server">
      </asp:gridview>
            
      <!-- 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="CustomersSqlDataSource"  
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City],
 [PostalCode], [Country] From [Customers]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
            
    </form>
  </body>
</html>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
System.Web.UI.WebControls 名前空間
GridView クラス
GridViewRowEventArgs クラス
GridView.RowCreated イベント
OnRowCreated
GridView.RowDataBound イベント
OnRowDataBound
その他の技術情報
イベントとデリゲート


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

英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「GridViewRowEventHandler デリゲート」の関連用語

GridViewRowEventHandler デリゲートのお隣キーワード
検索ランキング

   

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



GridViewRowEventHandler デリゲートのページの著作権

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

©2026 GRAS Group, Inc.RSS