DetailsViewRowCollection DetailsViewRowCollection DetailsViewRowCollection DetailsViewRowCollection Class

Definição

Representa uma coleção de objetos DetailsViewRow em um controle DetailsView.Represents a collection of DetailsViewRow objects in a DetailsView control.

public ref class DetailsViewRowCollection : System::Collections::ICollection
public class DetailsViewRowCollection : System.Collections.ICollection
type DetailsViewRowCollection = class
    interface ICollection
    interface IEnumerable
Public Class DetailsViewRowCollection
Implements ICollection
Herança
DetailsViewRowCollectionDetailsViewRowCollectionDetailsViewRowCollectionDetailsViewRowCollection
Implementações

Exemplos

O exemplo de código a seguir demonstra como iterar DetailsViewRow pelos objetos Rows na coleção de um DetailsView controle.The following code example demonstrates how to iterate through the DetailsViewRow objects in the Rows collection of a DetailsView control. O valor de cada linha é exibido na página.The value of each row is then displayed on the page.


<%@ 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)
    {
      // Iterate through the Rows collection and display
      // the value of each field.
      MessageLabel.Text = "The row values are: <br/><br/>";

      foreach (DetailsViewRow row in ItemDetailsView.Rows)
      {
        // 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 Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>DetailsViewRowCollection 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 Row Values"
        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>

<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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
    
      ' Iterate through the Rows collection and display
      ' the value of each field.
      MessageLabel.Text = "The row values are: <br/><br/>"
    
      Dim row As DetailsViewRow
    
      For Each row In ItemDetailsView.Rows
    
        ' 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/>"
    
      Next
    
    Else
      
      MessageLabel.Text = "No items."
    
    End If
    
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsViewRowCollection Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>DetailsViewRowCollection 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 Row Values"
        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>

Comentários

A DetailsViewRowCollection classe é usada para armazenar e gerenciar uma coleção de DetailsViewRow objetos em um DetailsView controle.The DetailsViewRowCollection class is used to store and manage a collection of DetailsViewRow objects in a DetailsView control. Cada linha em um DetailsView controle é representada por um DetailsViewRow objeto.Each row in a DetailsView control is represented by a DetailsViewRow object. O DetailsView controle usa a DetailsViewRowCollection classe para sua Rows propriedade.The DetailsView control uses the DetailsViewRowCollection class for its Rows property.

Observação

A Rows propriedade contém apenas as linhas de dados.The Rows property contains only the data rows. Para acessar a linha de cabeçalho, a linha do rodapé, a linha do pager superior e a linha HeaderRowdo pager TopPagerRowinferior, BottomPagerRow use as propriedades, FooterRow, e, respectivamente.To access the header row, footer row, top pager row, and bottom pager row, use the HeaderRow, FooterRow, TopPagerRow, and BottomPagerRow properties, respectively.

A DetailsViewRowCollection classe oferece suporte a várias maneiras de acessar os itens na coleção:The DetailsViewRowCollection class supports several ways to access the items in the collection:

  • Use o Item[Int32] indexador para recuperar diretamente um DetailsViewRow objeto da coleção em um índice de base zero específico.Use the Item[Int32] indexer to directly retrieve a DetailsViewRow object from the collection at a specific zero-based index.

  • Use o GetEnumerator método para recuperar um enumerador que pode ser usado para iterar pela coleção.Use the GetEnumerator method to retrieve an enumerator that can be used to iterate through the collection.

  • Use o CopyTo método para copiar os itens da coleção em uma matriz, que pode ser usada para acessar os itens na coleção.Use the CopyTo method to copy the items in the collection into an array, which can then be used to access the items in the collection.

Para determinar o número total de itens na coleção, use a Count propriedade.To determine the total number of items in the collection, use the Count property.

Construtores

DetailsViewRowCollection(ArrayList) DetailsViewRowCollection(ArrayList) DetailsViewRowCollection(ArrayList) DetailsViewRowCollection(ArrayList)

Inicializa uma nova instância da classe DetailsViewRowCollection usando o objeto ArrayList especificado.Initializes a new instance of the DetailsViewRowCollection class using the specified ArrayList object.

Propriedades

Count Count Count Count

Obtém o número de itens no objeto DetailsViewRowCollection.Gets the number of items in the DetailsViewRowCollection object.

IsReadOnly IsReadOnly IsReadOnly IsReadOnly

Obtém um valor que indica se as linhas no objeto DetailsViewRowCollection podem ser modificadas.Gets a value indicating whether the rows in the DetailsViewRowCollection object can be modified.

IsSynchronized IsSynchronized IsSynchronized IsSynchronized

Obtém um valor que indica se o objeto DetailsViewRowCollection é sincronizado (thread-safe).Gets a value indicating whether the DetailsViewRowCollection object is synchronized (thread safe).

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

Obtém o objeto DetailsViewRow da coleção no índice especificado.Gets the DetailsViewRow object from the collection at the specified index.

SyncRoot SyncRoot SyncRoot SyncRoot

Obtém o objeto usado para sincronizar o acesso à coleção.Gets the object used to synchronize access to the collection.

Métodos

CopyTo(DetailsViewRow[], Int32) CopyTo(DetailsViewRow[], Int32) CopyTo(DetailsViewRow[], Int32) CopyTo(DetailsViewRow[], Int32)

Copia os itens desse objeto DetailsViewRowCollection para o objeto Array especificado, começando no índice especificado no Array.Copies all the items from this DetailsViewRowCollection object to the specified Array object, starting at the specified index in the Array.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

Retorna um enumerador que contém todos os objetos DetailsViewRow no objeto DetailsViewRowCollection.Returns an enumerator that contains all DetailsViewRow objects in the DetailsViewRowCollection object.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serve como a função de hash padrão.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Obtém o Type da instância atual.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object.

(Inherited from Object)

Implantações explícitas de interface

ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32)

Copia os itens desse objeto DetailsViewRowCollection para o objeto Array especificado, começando no índice especificado no Array.Copies all the items from this DetailsViewRowCollection object to the specified Array object, starting at the specified index in the Array.

Métodos de Extensão

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

Converte os elementos de um IEnumerable para o tipo especificado.Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

Filtra os elementos de um IEnumerable com base em um tipo especificado.Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

Habilita a paralelização de uma consulta.Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

Converte um IEnumerable em um IQueryable.Converts an IEnumerable to an IQueryable.

Aplica-se a

Veja também