HtmlTableRowCollection HtmlTableRowCollection HtmlTableRowCollection HtmlTableRowCollection Class

Definição

Uma coleção de objetos HtmlTableRow que representam as linhas de um controle HtmlTable.A collection of HtmlTableRow objects that represent the rows of an HtmlTable control. Essa classe não pode ser herdada.This class cannot be inherited.

public ref class HtmlTableRowCollection sealed : System::Collections::ICollection
public sealed class HtmlTableRowCollection : System.Collections.ICollection
type HtmlTableRowCollection = class
    interface ICollection
    interface IEnumerable
Public NotInheritable Class HtmlTableRowCollection
Implements ICollection
Herança
HtmlTableRowCollectionHtmlTableRowCollectionHtmlTableRowCollectionHtmlTableRowCollection
Implementações

Exemplos

O exemplo de código a seguir demonstra como gerar dinamicamente o conteúdo de HtmlTable um controle adicionando linhas a uma HtmlTableRowCollection coleção.The following code example demonstrates how to dynamically generate the contents of an HtmlTable control by adding rows to an HtmlTableRowCollection collection. Observe que a Rows propriedade de uma tabela é o HtmlTableRowCollection objeto.Notice that the Rows property of a table is the HtmlTableRowCollection object.

<%@ Page Language="C#" AutoEventWireup="True" %>

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

   void Page_Load(Object sender, EventArgs e)
   {

     // Get the number of rows and columns selected by the user.
     int numrows = Convert.ToInt32(Select1.Value);
     int numcells = Convert.ToInt32(Select2.Value);

     // Iterate through the rows.
     for (int j = 0; j < numrows; j++)
     {

       // Create a new row and add it to the Rows collection.
       HtmlTableRow row = new HtmlTableRow();

       // Provide a different background color for alternating rows.
       if (j % 2 == 1)
         row.BgColor = "Gray";

       // Iterate through the cells of a row.
       for (int i = 0; i < numcells; i++)
       {
         // Create a new cell and add it to the Cells collection.
         HtmlTableCell cell = new HtmlTableCell();
         cell.Controls.Add(new LiteralControl("row " +
                           j.ToString() +
                           ", cell " +
                           i.ToString()));
         row.Cells.Add(cell);
       }
       Table1.Rows.Add(row);
     }
   }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>HtmlTableRowCollection Example</title>
</head>
<body>

   <form id="form1" runat="server">

      <h3>HtmlTableRowCollection Example</h3>

      <table id="Table1" 
             style="border-width:1; border-color:Black; padding:5"
             cellspacing="0"
             runat="server" />
        
      <hr />

      Select the number of rows and columns to create: <br /><br />

      Table rows:
      <select id="Select1" 
              runat="server">

         <option value="1">1</option>
         <option value="2">2</option>
         <option value="3">3</option>
         <option value="4">4</option>
         <option value="5">5</option>

      </select>

      &nbsp;&nbsp;

      Table cells:
      <select id="Select2" 
              runat="server">

         <option value="1">1</option>
         <option value="2">2</option>
         <option value="3">3</option>
         <option value="4">4</option>
         <option value="5">5</option>

      </select>
       
      <br /><br />
  
      <input type="submit" 
             value="Generate Table" 
             runat="server"/>

   </form>

</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>

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

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

    Dim i As Integer
    Dim j As Integer
    Dim row As HtmlTableRow
    Dim cell As HtmlTableCell

    ' Get the number of rows and columns selected by the user.
    Dim numrows As Integer = CInt(Select1.Value)
    Dim numcells As Integer = CInt(Select2.Value)

    ' Iterate through the rows.
    For j = 0 To numrows - 1

      ' Create a new row and add it to the Rows collection.
      row = New HtmlTableRow()

      ' Provide a different background color for alternating rows.
      If (j Mod 2) = 1 Then
        row.BgColor = "Gray"
      End If

      ' Iterate through the cells of a row.
      For i = 0 To numcells - 1
           
        ' Create a new cell and add it to the Cells collection.
        cell = New HtmlTableCell()
        cell.Controls.Add(New LiteralControl("row " & _
                                          j.ToString() & _
                                          ", cell " & _
                                          i.ToString()))
        row.Cells.Add(cell)
            
      Next i

      Table1.Rows.Add(row)
         
    Next j
      
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>HtmlTableRowCollection Example</title>
</head>
<body>

   <form id="form1" runat="server">

      <h3>HtmlTableRowCollection Example</h3>

      <table id="Table1" 
             style="border-width:1; border-color:Black; padding:5"
             cellspacing="0"
             runat="server" />
        
      <hr />

      Select the number of rows and columns to create: <br /><br />

      Table rows:
      <select id="Select1" 
              runat="server">

         <option value="1">1</option>
         <option value="2">2</option>
         <option value="3">3</option>
         <option value="4">4</option>
         <option value="5">5</option>

      </select>

      &nbsp;&nbsp;

      Table cells:
      <select id="Select2" 
              runat="server">

         <option value="1">1</option>
         <option value="2">2</option>
         <option value="3">3</option>
         <option value="4">4</option>
         <option value="5">5</option>

      </select>
       
      <br /><br />
  
      <input type="submit" 
             value="Generate Table" 
             runat="server"/>

   </form>

</body>
</html>

Comentários

Use a HtmlTableRowCollection classe para gerenciar programaticamente uma HtmlTableRow coleção de objetos que representam as linhas HtmlTable em um controle.Use the HtmlTableRowCollection class to programmatically manage a collection of HtmlTableRow objects that represent the rows in an HtmlTable control. Essa classe é normalmente usada para adicionar, remover ou modificar o conteúdo de uma linha em um HtmlTable controle.This class is commonly used to add, remove, or modify the contents of a row in an HtmlTable control.

Observação

Um HtmlTable controle contém uma Rows propriedade que representa uma coleção de HtmlTableRow objetos.An HtmlTable control contains a Rows property that represents a collection of HtmlTableRow objects. Cada HtmlTableRow representa uma linha individual na tabela.Each HtmlTableRow represents an individual row in the table. Um HtmlTableRow contém uma Cells propriedade que representa uma coleção de HtmlTableCell objetos.An HtmlTableRow contains a Cells property that represents a collection of HtmlTableCell objects. Esses objetos, por sua vez, representam as células individuais da tabela.These objects, in turn, represent the individual cells of the table. Para recuperar uma célula individual, primeiro obtenha o HtmlTableRow objeto, representando a linha que contém a célula, Rows da coleção do HtmlTable controle.To retrieve an individual cell, first get the HtmlTableRow object, representing the row containing the cell, from the Rows collection of the HtmlTable control. Em seguida, você pode HtmlTableCell obter o objeto, representando a célula na linha, Cells da coleção de HtmlTableRow.You can then get the HtmlTableCell object, representing the cell in the row, from the Cells collection of the HtmlTableRow.

Propriedades

Count Count Count Count

Obtém o número de objetos HtmlTableRow na coleção HtmlTableRowCollection.Gets the number of HtmlTableRow objects in the HtmlTableRowCollection collection.

IsReadOnly IsReadOnly IsReadOnly IsReadOnly

Obtém um valor que indica se a coleção HtmlTableRowCollection é somente leitura.Gets a value indicating whether the HtmlTableRowCollection collection is read-only.

IsSynchronized IsSynchronized IsSynchronized IsSynchronized

Obtém um valor que indica se o acesso à coleção HtmlTableRowCollection é sincronizado (thread-safe).Gets a value indicating whether access to the HtmlTableRowCollection collection is synchronized (thread safe).

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

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

SyncRoot SyncRoot SyncRoot SyncRoot

Obtém o objeto que pode ser usado para sincronizar o acesso à coleção HtmlTableRowCollection.Gets the object that can be used to synchronize access to the HtmlTableRowCollection collection.

Métodos

Add(HtmlTableRow) Add(HtmlTableRow) Add(HtmlTableRow) Add(HtmlTableRow)

Acrescenta o objeto HtmlTableRow especificado ao final da coleção HtmlTableRowCollection.Appends the specified HtmlTableRow object to the end of the HtmlTableRowCollection collection.

Clear() Clear() Clear() Clear()

Remove todos os objetos HtmlTableRow da coleção HtmlTableRowCollection.Removes all HtmlTableRow objects from the HtmlTableRowCollection collection.

CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32)

Copia os itens da coleção HtmlTableRowCollection no objeto Array especificado, começando no índice especificado na matriz.Copies the items from the HtmlTableRowCollection collection 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 objeto implementado por IEnumerator que contém todos os objetos HtmlTableRow na coleção HtmlTableRowCollection.Returns an IEnumerator-implemented object that contains all HtmlTableRow objects in the HtmlTableRowCollection collection.

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)
Insert(Int32, HtmlTableRow) Insert(Int32, HtmlTableRow) Insert(Int32, HtmlTableRow) Insert(Int32, HtmlTableRow)

Adiciona um objeto HtmlTableRow ao local especificado na coleção.Adds an HtmlTableRow object to the specified location in the collection.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
Remove(HtmlTableRow) Remove(HtmlTableRow) Remove(HtmlTableRow) Remove(HtmlTableRow)

Remove o objeto HtmlTableRow especificado da coleção HtmlTableRowCollection.Removes the specified HtmlTableRow object from the HtmlTableRowCollection collection.

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

Remove o objeto HtmlTableRow no índice especificado da coleção HtmlTableRowCollection.Removes the HtmlTableRow object at the specified index from the HtmlTableRowCollection collection.

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)

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