Assembly: System.Web (in System.Web.dll)
Thetype exposes the following members.
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|GetHashCode||Serves as the default hash function. (Inherited from Object.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
Before the GridView control can be rendered, a GridViewRow object must be created for each row in the control. The RowCreated event is raised each time a row in the GridView control is created. This allows you to provide an event-handling method that performs a custom routine, such as adding custom content to a row, whenever this event occurs.
Similarly, each row in the control must be bound to a record in the data source before the GridView control can be rendered. 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 object is passed to the event-handling method, which allows you to access the properties of the row that raised the event. To access a specific cell in the row, use the Cells property of the GridViewRow object contained in the Row property. You can also determine which row type (header row, data row, and so on) is being created by using the RowType property of the GridViewRow object.
For more information about handling events, see Consuming Events.
For a list of initial property values for an instance of , see the GridViewRowEventArgs constructor.
The following example demonstrates how to use the object passed to the event-handling method to access the properties of the row being bound to data.
<%@ Page language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <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 xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>GridView RowDataBound Example</title> </head> <body> <form id="form1" 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>