HtmlTableCellCollection Klass

Definition

En samling HtmlTableCell objekt som representerar cellerna i en enda rad i en HtmlTable kontroll. Det går inte att ärva den här klassen.

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
Arv
HtmlTableCellCollection
Implementeringar

Exempel

Följande kodexempel visar hur du dynamiskt genererar innehållet i en HtmlTable kontroll genom att lägga till celler i en HtmlTableCellCollection samling. Observera att egenskapen för Cells en rad, som representeras av ett HtmlTableRow objekt, är HtmlTableCellCollection samlingen.

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

Kommentarer

HtmlTableCellCollection Använd klassen för att programmatiskt hantera en samling HtmlTableCell objekt som representerar cellerna i en enskild rad i en HtmlTable kontroll. Den här klassen används ofta för att lägga till, ta bort eller ändra innehållet i en cell i en rad i en HtmlTable kontroll.

Note

En HtmlTable kontroll innehåller en Rows egenskap som innehåller en samling HtmlTableRow objekt. Varje HtmlTableRow objekt representerar en enskild rad i tabellen. Ett HtmlTableRow objekt innehåller en Cells egenskap som representerar en samling HtmlTableCell objekt. Dessa objekt representerar i sin tur enskilda celler i en rad. Hämta en enskild cell genom att först hämta objektet HtmlTableRow som representerar raden som innehåller cellen i tabellen (från Rows kontrollens HtmlTable samling). Du kan sedan hämta objektet HtmlTableCell som representerar cellen på raden (från Cells objektets HtmlTableRow samling).

Egenskaper

Name Description
Count

Hämtar antalet HtmlTableCell objekt i HtmlTableCellCollection samlingen.

IsReadOnly

Hämtar ett värde som anger om HtmlTableCellCollection samlingen är skrivskyddad.

IsSynchronized

Hämtar ett värde som anger om åtkomsten HtmlTableCellCollection till samlingen synkroniseras (trådsäker).

Item[Int32]

HtmlTableCell Hämtar objektet vid det angivna indexet HtmlTableCellCollection från samlingen.

SyncRoot

Hämtar det objekt som kan användas för att synkronisera åtkomsten HtmlTableCellCollection till samlingen.

Metoder

Name Description
Add(HtmlTableCell)

Lägger till det angivna HtmlTableCell objektet i slutet av HtmlTableCellCollection samlingen.

Clear()

Tar bort alla HtmlTableCell objekt från HtmlTableCellCollection samlingen.

CopyTo(Array, Int32)

Kopierar objekten HtmlTableCellCollection från samlingen till den angivna Array, som börjar med det angivna indexet Arrayi .

Equals(Object)

Avgör om det angivna objektet är lika med det aktuella objektet.

(Ärvd från Object)
GetEnumerator()

Returnerar ett IEnumerator-implementerat objekt som innehåller alla HtmlTableCell objekt i HtmlTableCellCollection samlingen.

GetHashCode()

Fungerar som standard-hash-funktion.

(Ärvd från Object)
GetType()

Hämtar den aktuella instansen Type .

(Ärvd från Object)
Insert(Int32, HtmlTableCell)

Lägger till det angivna HtmlTableCell objektet på den angivna indexplatsen för HtmlTableCellCollection samlingen.

MemberwiseClone()

Skapar en ytlig kopia av den aktuella Object.

(Ärvd från Object)
Remove(HtmlTableCell)

Tar bort det angivna HtmlTableCell objektet från HtmlTableCellCollection samlingen.

RemoveAt(Int32)

Tar HtmlTableCell bort objektet vid det angivna indexet HtmlTableCellCollection från samlingen.

ToString()

Returnerar en sträng som representerar det aktuella objektet.

(Ärvd från Object)

Tilläggsmetoder

Name Description
AsParallel(IEnumerable)

Möjliggör parallellisering av en fråga.

AsQueryable(IEnumerable)

Konverterar en IEnumerable till en IQueryable.

Cast<TResult>(IEnumerable)

Omvandlar elementen i en IEnumerable till den angivna typen.

OfType<TResult>(IEnumerable)

Filtrerar elementen i en IEnumerable baserat på en angiven typ.

Gäller för

Se även