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 DetailsViewRow this [
	int index
] { get; }
/** @property */
public DetailsViewRow get_Item (int index)

Not applicable.

Parameters

index

The index of the DetailsViewRow to retrieve from the collection.

Property Value

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="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void SubmitButton_Click(Object sender, EventArgs e)
  {

    // Use the Count property to determine whether the
    // Rows collection contains any item.
    if (ItemDetailsView.Rows.Count > 0)
    {
      // Display the field value in the first data row.
     
      // Use the indexer to get the first data row 
      // (index 0) from the Rows collection.
      DetailsViewRow row = 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/>";
    }
    else
    {
      MessageLabel.Text = "No items.";
    }

  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsViewRowCollection Indexer Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>DetailsViewRowCollection Indexer Example</h3>
  
      <asp:detailsview id="ItemDetailsView"
        datasourceid="DetailsViewSource"
        allowpaging="true"
        autogeneraterows="false" 
        runat="server">
        <fields>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID"/>
          <asp:boundfield datafield="CompanyName"
            headertext="Company Name"/>
          <asp:boundfield datafield="Address"
            headertext="Address"/>
          <asp:boundfield datafield="City"
            headertext="City"/>
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"
            headertext="Country"/>
        </fields>
      </asp:detailsview>
      
      <br/>
      
      <asp:button id="SubmitButton" 
        text="Display Value"
        onclick="SubmitButton_Click"
        runat="server"/>
        
      <br/><br/>
      
      <asp:label id="MessageLabel"
        forecolor="Red"
        runat="server"/>
      
      <!-- 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]"
        connectionstring=
          "<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>  
  
    </form>
  </body>
</html>

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft