GridViewRowEventHandler デリゲート
アセンブリ: System.Web (system.web.dll 内)

/** @delegate */ public delegate void GridViewRowEventHandler ( Object sender, GridViewRowEventArgs e )

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>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からGridViewRowEventHandler デリゲートを検索する場合は、下記のリンクをクリックしてください。

- GridViewRowEventHandler デリゲートのページへのリンク