Compartir por


HtmlTableCellCollection Clase

Definición

Colección de HtmlTableCell objetos que representan las celdas de una sola fila de un HtmlTable control. Esta clase no puede heredarse.

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
Herencia
HtmlTableCellCollection
Implementaciones

Ejemplos

En el ejemplo de código siguiente se muestra cómo generar dinámicamente el contenido de un HtmlTable control agregando celdas a una HtmlTableCellCollection colección. Observe que la Cells propiedad de una fila, representada por un HtmlTableRow objeto , es la HtmlTableCellCollection colección .

<%@ 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>

Comentarios

Use la HtmlTableCellCollection clase para administrar mediante programación una colección de HtmlTableCell objetos que representan las celdas de una sola fila de un HtmlTable control. Esta clase se usa normalmente para agregar, quitar o modificar el contenido de una celda en una fila de un HtmlTable control.

Nota:

Un HtmlTable control contiene una Rows propiedad que contiene una colección de HtmlTableRow objetos . Cada HtmlTableRow objeto representa una fila individual de la tabla. Un HtmlTableRow objeto contiene una Cells propiedad que representa una colección de HtmlTableCell objetos . Estos objetos, a su vez, representan las celdas individuales de una fila. Para recuperar una celda individual, obtenga primero el HtmlTableRow objeto que representa la fila que contiene la celda de la tabla (de la Rows colección del HtmlTable control). A continuación, puede obtener el HtmlTableCell objeto que representa la celda de la fila (de la Cells colección del HtmlTableRow objeto ).

Propiedades

Nombre Description
Count

Obtiene el número de objetos de HtmlTableCell la HtmlTableCellCollection colección.

IsReadOnly

Obtiene un valor que indica si la HtmlTableCellCollection colección es de solo lectura.

IsSynchronized

Obtiene un valor que indica si el acceso a la HtmlTableCellCollection colección está sincronizado (seguro para subprocesos).

Item[Int32]

Obtiene el HtmlTableCell objeto en el índice especificado de la HtmlTableCellCollection colección.

SyncRoot

Obtiene el objeto que se puede usar para sincronizar el acceso a la HtmlTableCellCollection colección.

Métodos

Nombre Description
Add(HtmlTableCell)

Anexa el objeto especificado HtmlTableCell al final de la HtmlTableCellCollection colección.

Clear()

Quita todos los HtmlTableCell objetos de la HtmlTableCellCollection colección.

CopyTo(Array, Int32)

Copia los elementos de la HtmlTableCellCollection colección en el especificadoArray, empezando por el índice especificado en .Array

Equals(Object)

Determina si el objeto especificado es igual al objeto actual.

(Heredado de Object)
GetEnumerator()

Devuelve un IEnumeratorobjeto implementado que contiene todos los HtmlTableCell objetos de la HtmlTableCellCollection colección.

GetHashCode()

Actúa como función hash predeterminada.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
Insert(Int32, HtmlTableCell)

Agrega el objeto especificado HtmlTableCell en la ubicación de índice especificada de la HtmlTableCellCollection colección.

MemberwiseClone()

Crea una copia superficial del Objectactual.

(Heredado de Object)
Remove(HtmlTableCell)

Quita el objeto especificado HtmlTableCell de la HtmlTableCellCollection colección.

RemoveAt(Int32)

Quita el HtmlTableCell objeto en el índice especificado de la HtmlTableCellCollection colección.

ToString()

Devuelve una cadena que representa el objeto actual.

(Heredado de Object)

Métodos de extensión

Nombre Description
AsParallel(IEnumerable)

Habilita la paralelización de una consulta.

AsQueryable(IEnumerable)

Convierte un IEnumerable en un IQueryable.

Cast<TResult>(IEnumerable)

Convierte los elementos de un IEnumerable al tipo especificado.

OfType<TResult>(IEnumerable)

Filtra los elementos de un IEnumerable en función de un tipo especificado.

Se aplica a

Consulte también