This documentation is archived and is not being maintained.

DetailsView.DataItem Property

Note: This property is new in the .NET Framework version 2.0.

Gets the data item bound to the DetailsView control.

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

public virtual Object DataItem { get; }
/** @property */
public Object get_DataItem ()

public function get DataItem () : Object

Property Value

An Object that represents the data item bound to the DetailsView control.

Use the DataItem property to access the data item bound to the DetailsView control. The data item is often used to access the field values of the current record directly. The type of the Object returned by this property varies depending on the data source. For example, when a SqlDataSource control is bound to the DetailsView control, a DataRowView object is returned.


This property is available only after data binding has occurred. Before data binding occurs, this property returns a null reference (Nothing in Visual Basic). This property is also not applicable when the DetailsView control is in insert mode and returns a null reference (Nothing in Visual Basic).

The following code example demonstrates how to use the DataItem property to determine the value of a field in the data item.

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

<script runat="server">
    protected void CustomerDetailView_DataBound(object sender, 
      EventArgs e)
        DataRowView rowView = (DataRowView)CustomerDetailView.DataItem;
        if (rowView.Row[0].ToString() == "SpecialID")
            CustomerDetailView.FieldHeaderStyle.BackColor = 

    <form id="Form1" runat="server">
      <h3>DetailsView ModeChanging Example</h3>
        <asp:detailsview id="CustomerDetailView"
          <fieldheaderstyle backcolor="Navy"
        <!-- 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="DetailsViewSource" runat="server" 
            "<%$ ConnectionStrings:NorthWindConnectionString%>"
          InsertCommand="INSERT INTO [Customers]([CustomerID],
            [CompanyName], [Address], [City], [PostalCode], [Country]) 
            VALUES (@CustomerID, @CompanyName, @Address, @City, 
            @PostalCode, @Country)"
          SelectCommand="Select [CustomerID], [CompanyName], 
            [Address], [City], [PostalCode], [Country] From 

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.

.NET Framework

Supported in: 2.0