GridViewRowCollection GridViewRowCollection GridViewRowCollection GridViewRowCollection Class

Definição

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

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

Exemplos

O exemplo a seguir demonstra como iterar pela Rows coleção de um GridView controle e exibir os valores de uma coluna na página.The following example demonstrates how to iterate through the Rows collection of a GridView control and display the values of a column 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 AuthorsGridView_RowCreated(Object sender, GridViewRowEventArgs e)
  {
    if (e.Row.RowType == DataControlRowType.Footer)
    {      
      
      // Get the number of items in the Rows collection.
      int count = AuthorsGridView.Rows.Count;

      // If the GridView control contains any records, display 
      // the last name of each author in the GridView control.
      if (count > 0)
      {      
        Message.Text = "The authors are:<br />";
        
        foreach (GridViewRow row in AuthorsGridView.Rows)
        {
          Message.Text += row.Cells[0].Text + "<br />";
        }
      }
      
    }
  }

</script>

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

      <table>
        <tr>
          <td>
            <asp:gridview id="AuthorsGridView" 
              datasourceid="AuthorsSqlDataSource" 
              autogeneratecolumns="false"
              onrowcreated="AuthorsGridView_RowCreated"  
              runat="server"> 
                     
              <columns>
                <asp:boundfield datafield="au_lname"
                  headertext="Last Name"/>
                <asp:boundfield datafield="au_fname"
                  headertext="First Name"/>
              </columns>
                                    
            </asp:gridview>
          </td>
          <td>
            <asp:label id="Message" 
              forecolor="Red"
              runat="server"/>
          </td>
        </tr>
      </table>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="AuthorsSqlDataSource"  
        selectcommand="SELECT [au_lname], [au_fname] FROM [authors] WHERE [state]='CA'"
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
          
    </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 AuthorsGridView_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

    If e.Row.RowType = DataControlRowType.Footer Then
      
      ' Get the number of items in the Rows collection.
      Dim count As Integer = AuthorsGridView.Rows.Count

      ' If the GridView control contains any records, display 
      ' the last name of each author in the GridView control.
      If count > 0 Then
           
        Message.Text = "The authors are:<br />"
        
        Dim row As GridViewRow
        For Each row In AuthorsGridView.Rows
        
          Message.Text &= row.Cells(0).Text & "<br />"
        
        Next
        
      End If
        
    End If
        
  End Sub

</script>

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

      <table>
        <tr>
          <td>
            <asp:gridview id="AuthorsGridView" 
              datasourceid="AuthorsSqlDataSource" 
              autogeneratecolumns="false"
              onrowcreated="AuthorsGridView_RowCreated"  
              runat="server"> 
                     
              <columns>
                <asp:boundfield datafield="au_lname"
                  headertext="Last Name"/>
                <asp:boundfield datafield="au_fname"
                  headertext="First Name"/>
              </columns>
                                    
            </asp:gridview>
          </td>
          <td>
            <asp:label id="Message" 
              forecolor="Red"
              runat="server"/>
          </td>
        </tr>
      </table>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="AuthorsSqlDataSource"  
        selectcommand="SELECT [au_lname], [au_fname] FROM [authors] WHERE [state]='CA'"
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
          
    </form>
  </body>
</html>

Comentários

A GridViewRowCollection classe é usada para armazenar e gerenciar uma coleção de GridViewRow objetos em um GridView controle.The GridViewRowCollection class is used to store and manage a collection of GridViewRow objects in a GridView control. Cada linha em um GridView controle é representada por um GridViewRow objeto.Each row in a GridView control is represented by a GridViewRow object. O GridView controle armazena todas as suas linhas de dados Rows na coleção.The GridView control stores all of its data rows in the Rows collection.

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

  • Use o Item[Int32] indexador para recuperar diretamente um GridViewRow objeto em um índice de base zero específico.Use the Item[Int32] indexer to directly retrieve a GridViewRow object 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 um System.Array objeto, que pode ser usado para acessar os itens na coleção.Use the CopyTo method to copy the items in the collection into an System.Array object, 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 PropriedadeTo determine the total number of items in the collection, use the Count property

Construtores

GridViewRowCollection(ArrayList) GridViewRowCollection(ArrayList) GridViewRowCollection(ArrayList) GridViewRowCollection(ArrayList)

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

Propriedades

Count Count Count Count

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

IsReadOnly IsReadOnly IsReadOnly IsReadOnly

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

IsSynchronized IsSynchronized IsSynchronized IsSynchronized

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

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

Obtém o objeto GridViewRow no índice especificado.Gets the GridViewRow object 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(GridViewRow[], Int32) CopyTo(GridViewRow[], Int32) CopyTo(GridViewRow[], Int32) CopyTo(GridViewRow[], Int32)

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

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 GridViewRow no GridViewRowCollection.Returns an enumerator that contains all GridViewRow objects in the GridViewRowCollection.

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)

Para obter uma descrição desse membro, consulte CopyTo(Array, Int32).For a description of this member, see CopyTo(Array, Int32).

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