This documentation is archived and is not being maintained.

GridViewRow.DataItem Property

Gets the underlying data object to which the GridViewRow object is bound.

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

public virtual Object DataItem { get; set; }
<asp:GridViewRow DataItem="Object" />

Property Value

Type: System.Object
An Object that represents the underlying data object to which the GridViewRow object is bound.

Use the DataItem property to access the properties of the underlying data object to which the GridViewRow object is bound. The DataItem property is only available during and after the RowDataBound event of a GridView control.


This property applies only to data rows.

The following example demonstrates how to use the DataItem property to retrieve a field value. The value is then used to pre-select an item in a DropDownList control displayed when a row is in edit mode.

<%@ Page language="C#" %>
<%@ import namespace="System.Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

  void AuthorsGridView_RowDataBound (Object sender, GridViewRowEventArgs e)
    // Check for a row in edit mode.
    if(e.Row.RowState == DataControlRowState.Edit)
      // Preselect the DropDownList control with the state value
      // for the current row.

      // Retrieve the underlying data item. In this example
      // the underlying data item is a DataRowView object. 
      DataRowView rowView = (DataRowView)e.Row.DataItem;

      // Retrieve the state value for the current row. 
      String state = rowView["state"].ToString();

      // Retrieve the DropDownList control from the current row. 
      DropDownList list = (DropDownList)e.Row.FindControl("StatesList");

      // Find the ListItem object in the DropDownList control with the 
      // state value and select the item.
      ListItem item = list.Items.FindByText(state);
      list.SelectedIndex = list.Items.IndexOf(item);

  void AuthorsGridView_RowUpdating(Object sender, GridViewUpdateEventArgs e)
    // Retrieve the row being edited.
    GridViewRow row = AuthorsGridView.Rows[AuthorsGridView.EditIndex];

    // Retrieve the DropDownList control from the row.
    DropDownList list = (DropDownList)row.FindControl("StatesList");

    // Add the selected value of the DropDownList control to 
    // the NewValues collection. The NewValues collection is
    // passed to the data source control, which then updates the 
    // data source.
    e.NewValues["state"] = list.SelectedValue;


<html xmlns="" >
  <head runat="server">
    <title>GridViewRow DataItem Example</title>
    <form id="form1" runat="server">

      <h3>GridViewRow DataItem Example</h3>

      <asp:gridview id="AuthorsGridView" 

          <asp:boundfield datafield="au_lname"
            headertext="Last Name"/>
          <asp:boundfield datafield="au_fname"
            headertext="First Name"/>
          <asp:templatefield headertext="State">
              <asp:dropdownlist id="StatesList"
              <asp:sqldatasource id="StatesSqlDataSource"  
                selectcommand="SELECT Distinct [state] FROM [authors]"
                connectionstring="server=localhost;database=pubs;integrated security=SSPI"


      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="AuthorsSqlDataSource"  
        selectcommand="SELECT [au_id], [au_lname], [au_fname], [state] FROM [authors]"
        updatecommand="UPDATE authors SET [au_lname]=@au_lname, [au_fname]=@au_fname, [state]=@state WHERE au_id=@au_id"
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.