GridView.RowDataBound イベント
アセンブリ: System.Web (system.web.dll 内)

Dim instance As GridView Dim handler As GridViewRowEventHandler AddHandler instance.RowDataBound, handler
public: event GridViewRowEventHandler^ RowDataBound { void add (GridViewRowEventHandler^ value); void remove (GridViewRowEventHandler^ value); }

GridView コントロールの表示前に、コントロールの各行をデータ ソースのレコードにバインドする必要があります。RowDataBound イベントは、(GridViewRow オブジェクトによって表される) データ行が GridView コントロールのデータにバインドされたときに発生します。これにより、このイベントが発生するたびにカスタム ルーチン (行にバインドされたデータの値を変更するなど) を実行するイベント処理メソッドを提供できます。
GridViewRowEventArgs オブジェクトがイベント処理メソッドに渡されることにより、バインドされる行のプロパティにアクセスできます。行の特定のセルにアクセスするには、GridViewRowEventArgs オブジェクトの Cells プロパティを使用します。RowType プロパティを使用して、バインドされる行の種類 (ヘッダー行、データ行など) を確認できます。
イベント処理の詳細については、「イベントの利用」を参照してください。
Topic | Location |
---|---|
方法 : GridView Web サーバー コントロールの列幅を動的に設定する | ASP .NET Web アプリケーションの作成 |

RowDataBound イベントを使用して、GridView コントロールに表示される前にデータ ソースのフィールドの値を変更する方法を次のコード例に示します。
<%@ 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に収録されているすべての辞書からGridView.RowDataBound イベントを検索する場合は、下記のリンクをクリックしてください。

- GridView.RowDataBound イベントのページへのリンク