HtmlTableCellCollection Classe
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Collection d’objets HtmlTableCell qui représentent les cellules d’une seule ligne d’un HtmlTable contrôle. Cette classe ne peut pas être héritée.
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
- Héritage
-
HtmlTableCellCollection
- Implémente
Exemples
L’exemple de code suivant montre comment générer dynamiquement le contenu d’un HtmlTable contrôle en ajoutant des cellules à une HtmlTableCellCollection collection. Notez que la Cells propriété d’une ligne, représentée par un HtmlTableRow objet, est la HtmlTableCellCollection collection.
<%@ 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>
Remarques
Utilisez la HtmlTableCellCollection classe pour gérer par programmation une collection d’objets HtmlTableCell qui représentent les cellules d’une seule ligne dans un HtmlTable contrôle. Cette classe est couramment utilisée pour ajouter, supprimer ou modifier le contenu d’une cellule dans une ligne d’un HtmlTable contrôle.
Note
Un HtmlTable contrôle contient une Rows propriété qui contient une collection d’objets HtmlTableRow . Chaque HtmlTableRow objet représente une ligne individuelle dans la table. Un HtmlTableRow objet contient une Cells propriété qui représente une collection d’objets HtmlTableCell . Ces objets représentent à leur tour les cellules individuelles d’une ligne. Pour récupérer une cellule individuelle, obtenez d’abord l’objet HtmlTableRow qui représente la ligne contenant la cellule du tableau (à partir de la Rows collection du HtmlTable contrôle). Vous pouvez ensuite obtenir l’objet HtmlTableCell qui représente la cellule de la ligne (à partir de la Cells collection de l’objet HtmlTableRow ).
Propriétés
| Nom | Description |
|---|---|
| Count |
Obtient le nombre d’objets HtmlTableCell de la HtmlTableCellCollection collection. |
| IsReadOnly |
Obtient une valeur indiquant si la HtmlTableCellCollection collection est en lecture seule. |
| IsSynchronized |
Obtient une valeur indiquant si l’accès à la HtmlTableCellCollection collection est synchronisé (thread safe). |
| Item[Int32] |
Obtient l’objet HtmlTableCell à l’index spécifié de la HtmlTableCellCollection collection. |
| SyncRoot |
Obtient l’objet qui peut être utilisé pour synchroniser l’accès à la HtmlTableCellCollection collection. |
Méthodes
| Nom | Description |
|---|---|
| Add(HtmlTableCell) |
Ajoute l’objet spécifié HtmlTableCell à la fin de la HtmlTableCellCollection collection. |
| Clear() |
Supprime tous les HtmlTableCell objets de la HtmlTableCellCollection collection. |
| CopyTo(Array, Int32) |
Copie les éléments de la HtmlTableCellCollection collection vers l’index spécifié Array, en commençant par l’index spécifié dans le Array. |
| Equals(Object) |
Détermine si l’objet spécifié est égal à l’objet actuel. (Hérité de Object) |
| GetEnumerator() |
Retourne un IEnumeratorobjet implémenté qui contient tous les HtmlTableCell objets de la HtmlTableCellCollection collection. |
| GetHashCode() |
Sert de fonction de hachage par défaut. (Hérité de Object) |
| GetType() |
Obtient la Type de l’instance actuelle. (Hérité de Object) |
| Insert(Int32, HtmlTableCell) |
Ajoute l’objet spécifié HtmlTableCell à l’emplacement d’index spécifié de la HtmlTableCellCollection collection. |
| MemberwiseClone() |
Crée une copie superficielle du Objectactuel. (Hérité de Object) |
| Remove(HtmlTableCell) |
Supprime l’objet spécifié HtmlTableCell de la HtmlTableCellCollection collection. |
| RemoveAt(Int32) |
Supprime l’objet à l’index HtmlTableCell spécifié de la HtmlTableCellCollection collection. |
| ToString() |
Retourne une chaîne qui représente l’objet actuel. (Hérité de Object) |
Méthodes d’extension
| Nom | Description |
|---|---|
| AsParallel(IEnumerable) |
Active la parallélisation d’une requête. |
| AsQueryable(IEnumerable) |
Convertit un IEnumerable en IQueryable. |
| Cast<TResult>(IEnumerable) |
Convertit les éléments d’un IEnumerable en type spécifié. |
| OfType<TResult>(IEnumerable) |
Filtre les éléments d’une IEnumerable en fonction d’un type spécifié. |