GridView.RowDataBound Event
Assembly: System.Web (in system.web.dll)
'Declaration Public Event RowDataBound As GridViewRowEventHandler 'Usage Dim instance As GridView Dim handler As GridViewRowEventHandler AddHandler instance.RowDataBound, handler
/** @event */ public void add_RowDataBound (GridViewRowEventHandler value) /** @event */ public void remove_RowDataBound (GridViewRowEventHandler value)
JScript supports the use of events, but not the declaration of new ones.
Before the GridView control can be rendered, each row in the control must be bound to a record in the data source. The RowDataBound event is raised when a data row (represented by a GridViewRow object) is bound to data in the GridView control. This allows you to provide an event-handling method that performs a custom routine, such as modifying the values of the data bound to the row, whenever this event occurs.
A GridViewRowEventArgs object is passed to the event-handling method, which allows you to access the properties of the row being bound. To access a specific cell in the row, use the Cells property of the GridViewRowEventArgs object. You can determine which row type (header row, data row, and so on) is being bound by using the RowType property.
For more information about handling events, see Consuming Events.
| Topic | Location |
|---|---|
| How to: Set GridView Web Server Control Column Width Dynamically | Building ASP .NET Web Applications |
| How to: Set GridView Web Server Control Column Width Dynamically | Building ASP .NET Web Applications |
The following code example demonstrates how to use the RowDataBound event to modify the value of a field in the data source before it is displayed in a GridView control.
<%@ 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>
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
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.