HtmlTableCellCollection Klasa

Definicja

Kolekcja HtmlTableCell obiektów reprezentujących komórki w jednym wierszu kontrolki HtmlTable . Klasa ta nie może być dziedziczona.

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
Dziedziczenie
HtmlTableCellCollection
Implementuje

Przykłady

Poniższy przykład kodu przedstawia sposób dynamicznego HtmlTable generowania zawartości kontrolki przez dodanie komórek do HtmlTableCellCollection kolekcji. Zwróć uwagę, że Cells właściwość wiersza reprezentowana przez obiekt jest kolekcją HtmlTableRow HtmlTableCellCollection .

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

Uwagi

HtmlTableCellCollection Klasa służy do programowego zarządzania kolekcją HtmlTableCell obiektów reprezentujących komórki jednego wiersza w kontrolceHtmlTable. Ta klasa jest często używana do dodawania, usuwania lub modyfikowania zawartości komórki w wierszu kontrolki HtmlTable .

Uwaga

Kontrolka HtmlTable zawiera właściwość zawierającą Rows kolekcję HtmlTableRow obiektów. Każdy HtmlTableRow obiekt reprezentuje pojedynczy wiersz w tabeli. Obiekt HtmlTableRow zawiera Cells właściwość reprezentującą kolekcję HtmlTableCell obiektów. Te obiekty reprezentują z kolei poszczególne komórki wiersza. Aby pobrać pojedynczą komórkę, najpierw pobierz HtmlTableRow obiekt reprezentujący wiersz zawierający komórkę w tabeli (z Rows kolekcji kontrolki HtmlTable ). Następnie można pobrać HtmlTableCell obiekt reprezentujący komórkę w wierszu (z Cells kolekcji HtmlTableRow obiektu).

Właściwości

Count

Pobiera liczbę HtmlTableCell obiektów w kolekcji HtmlTableCellCollection .

IsReadOnly

Pobiera wartość wskazującą, czy HtmlTableCellCollection kolekcja jest tylko do odczytu.

IsSynchronized

Pobiera wartość wskazującą, czy dostęp do HtmlTableCellCollection kolekcji jest synchronizowany (bezpieczny wątek).

Item[Int32]

HtmlTableCell Pobiera obiekt w określonym indeksie z kolekcjiHtmlTableCellCollection.

SyncRoot

Pobiera obiekt, który może służyć do synchronizowania dostępu do HtmlTableCellCollection kolekcji.

Metody

Add(HtmlTableCell)

Dołącza określony HtmlTableCell obiekt na końcu kolekcji HtmlTableCellCollection .

Clear()

Usuwa wszystkie HtmlTableCell obiekty z kolekcji HtmlTableCellCollection .

CopyTo(Array, Int32)

Kopiuje elementy z HtmlTableCellCollection kolekcji do określonego Array, począwszy od określonego indeksu w obiekcie Array.

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetEnumerator()

IEnumeratorZwraca obiekt implementowany, który zawiera wszystkie HtmlTableCell obiekty w kolekcjiHtmlTableCellCollection.

GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
Insert(Int32, HtmlTableCell)

Dodaje określony HtmlTableCell obiekt w określonej lokalizacji indeksu HtmlTableCellCollection kolekcji.

MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
Remove(HtmlTableCell)

Usuwa określony HtmlTableCell obiekt z kolekcji HtmlTableCellCollection .

RemoveAt(Int32)

HtmlTableCell Usuwa obiekt w określonym indeksie z kolekcjiHtmlTableCellCollection.

ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Metody rozszerzania

Cast<TResult>(IEnumerable)

Rzutuje elementy elementu IEnumerable na określony typ.

OfType<TResult>(IEnumerable)

Filtruje elementy IEnumerable elementu na podstawie określonego typu.

AsParallel(IEnumerable)

Umożliwia równoległość zapytania.

AsQueryable(IEnumerable)

Konwertuje element IEnumerable na .IQueryable

Dotyczy

Zobacz też