GridViewRowEventArgs Class
Collapse the table of content
Expand the table of content

GridViewRowEventArgs Class

Provides data for the RowCreated and RowDataBound events.


Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public class GridViewRowEventArgs : EventArgs

The GridViewRowEventArgs type exposes the following members.

Public methodGridViewRowEventArgsInitializes a new instance of the GridViewRowEventArgs class.

Public propertyRowGets the row being created or data-bound.

Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns 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 GridViewRowEventArgs 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 GridViewRowEventArgs, see the GridViewRowEventArgs constructor.

The following example demonstrates how to use the GridViewRowEventArgs object passed to the event-handling method to access the properties of the row being bound to data.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<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>";




<html xmlns="" >
  <head runat="server">
    <title>GridView RowDataBound Example</title>
    <form id="form1" runat="server">

      <h3>GridView RowDataBound Example</h3>

      <asp:gridview id="CustomersGridView" 

      <!-- 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%>"


.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
© 2015 Microsoft