Compartilhar via


HtmlTableCellCollection Classe

Definição

Uma coleção de HtmlTableCell objetos que representam as células em uma única linha de um HtmlTable controle. Essa classe não pode ser herdada.

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

Exemplos

O exemplo de código a seguir demonstra como gerar dinamicamente o conteúdo de um HtmlTable controle adicionando células a uma HtmlTableCellCollection coleção. Observe que a Cells propriedade de uma linha, representada por um HtmlTableRow objeto, é a HtmlTableCellCollection coleção.

<%@ 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>HtmlTableCellCollection Example</title>
</head>
<body>

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

      <h3>HtmlTableCellCollection 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>

        

      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>HtmlTableCellCollection Example</title>
</head>
<body>

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

      <h3>HtmlTableCellCollection 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>

        

      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 HtmlTableCellCollection classe para gerenciar programaticamente uma coleção de HtmlTableCell objetos que representam as células de uma única linha em um HtmlTable controle. Essa classe é comumente usada para adicionar, remover ou modificar o conteúdo de uma célula em uma linha de um HtmlTable controle.

Observação

Um HtmlTable controle contém uma Rows propriedade que contém uma coleção de HtmlTableRow objetos. Cada HtmlTableRow objeto representa uma linha individual na tabela. Um HtmlTableRow objeto contém uma Cells propriedade que representa uma coleção de HtmlTableCell objetos. Esses objetos, por sua vez, representam as células individuais de uma linha. Para recuperar uma célula individual, primeiro obtenha o HtmlTableRow objeto que representa a linha que contém a célula na tabela (da Rows coleção do HtmlTable controle). Em seguida, você pode obter o HtmlTableCell objeto que representa a célula na linha (da Cells coleção do HtmlTableRow objeto).

Propriedades

Nome Description
Count

Obtém o número de HtmlTableCell objetos na HtmlTableCellCollection coleção.

IsReadOnly

Obtém um valor que indica se a HtmlTableCellCollection coleção é somente leitura.

IsSynchronized

Obtém um valor que indica se o HtmlTableCellCollection acesso à coleção é sincronizado (thread safe).

Item[Int32]

Obtém o HtmlTableCell objeto no índice especificado da HtmlTableCellCollection coleção.

SyncRoot

Obtém o objeto que pode ser usado para sincronizar o HtmlTableCellCollection acesso à coleção.

Métodos

Nome Description
Add(HtmlTableCell)

Acrescenta o objeto especificado HtmlTableCell ao final da HtmlTableCellCollection coleção.

Clear()

Remove todos os HtmlTableCell objetos da HtmlTableCellCollection coleção.

CopyTo(Array, Int32)

Copia os itens da HtmlTableCellCollection coleção para o especificado Array, começando com o índice especificado no Array.

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetEnumerator()

Retorna um IEnumeratorobjeto implementado que contém todos os HtmlTableCell objetos na HtmlTableCellCollection coleção.

GetHashCode()

Serve como a função de hash padrão.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
Insert(Int32, HtmlTableCell)

Adiciona o objeto especificado HtmlTableCell no local de índice especificado da HtmlTableCellCollection coleção.

MemberwiseClone()

Cria uma cópia superficial do Objectatual.

(Herdado de Object)
Remove(HtmlTableCell)

Remove o objeto especificado HtmlTableCell da HtmlTableCellCollection coleção.

RemoveAt(Int32)

Remove o HtmlTableCell objeto no índice especificado da HtmlTableCellCollection coleção.

ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Métodos de Extensão

Nome Description
AsParallel(IEnumerable)

Habilita a paralelização de uma consulta.

AsQueryable(IEnumerable)

Converte um IEnumerable em um IQueryable.

Cast<TResult>(IEnumerable)

Converte os elementos de um IEnumerable para o tipo especificado.

OfType<TResult>(IEnumerable)

Filtra os elementos de um IEnumerable com base em um tipo especificado.

Aplica-se a

Confira também