Export (0) Print
Expand All

DetailsViewRowCollection.Item Property

Gets the DetailsViewRow object from the collection at the specified index.

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

Public ReadOnly Property Item ( _
	index As Integer _
) As DetailsViewRow


Type: System.Int32

The index of the DetailsViewRow to retrieve from the collection.

Property Value

Type: System.Web.UI.WebControls.DetailsViewRow
The DetailsViewRow at the specified index in the collection.

Use this indexer to retrieve a DetailsViewRow object from the collection at the specified index, using array notation.

The following code example demonstrates how to use the indexer to retrieve a DetailsViewRow object from the collection at a specific index.

<%@ page language="VB" %>

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

  Sub SubmitButton_Click(ByVal sender As Object, ByVal e As EventArgs)

    ' Use the Count property to determine whether the
    ' Rows collection contains any item.
    If ItemDetailsView.Rows.Count > 0 Then

      ' Display the field value in the first data row.

      ' Use the indexer to get the first data row 
      ' (index 0) from the Rows collection.
      Dim row As DetailsViewRow = ItemDetailsView.Rows(0)

      MessageLabel.Text = "The field value for the first row is: <br/><br/>"

      ' Use the Text property to access the value of 
      ' each cell. In this example, the cells in the 
      ' first column (index 0) contains the field names, 
      ' while the cells in the second column (index 1)
      ' contains the field value. 
      MessageLabel.Text &= row.Cells(0).Text & " = " & _
        row.Cells(1).Text & "<br/>"


      MessageLabel.Text = "No items."

    End If

  End Sub


<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsViewRowCollection Indexer Example</title>
    <form id="form1" runat="server">

      <h3>DetailsViewRowCollection Indexer Example</h3>

      <asp:detailsview id="ItemDetailsView"
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID"/>
          <asp:boundfield datafield="CompanyName"
            headertext="Company Name"/>
          <asp:boundfield datafield="Address"
          <asp:boundfield datafield="City"
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"


      <asp:button id="SubmitButton" 
        text="Display Value"


      <asp:label id="MessageLabel"

      <!-- 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"
        selectcommand="Select [CustomerID], [CompanyName], [Address], 
          [City], [PostalCode], [Country] From [Customers]"
          "<%$ ConnectionStrings:NorthWindConnectionString%>" 


.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

© 2014 Microsoft