HtmlTableCellCollection 类

定义

HtmlTableCell 对象的集合,这些对象表示 HtmlTable 控件的一个行中的单元格。A collection of HtmlTableCell objects that represent the cells in a single row of an HtmlTable control. 此类不能被继承。This class cannot be inherited.

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
继承
HtmlTableCellCollection
实现

示例

下面的代码示例演示如何通过向HtmlTable HtmlTableCellCollection集合添加单元格来动态生成控件的内容。The following code example demonstrates how to dynamically generate the contents of an HtmlTable control by adding cells to an HtmlTableCellCollection collection. 请注意, CellsHtmlTableRow对象表示的行的属性是HtmlTableCellCollection集合。Notice that the Cells property of a row, represented by an HtmlTableRow object, is the 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>

      &nbsp;&nbsp;

      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>

      &nbsp;&nbsp;

      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>

注解

使用类以编程方式管理HtmlTableCell对象的集合, 这些对象表示HtmlTable控件中单个行的单元格。 HtmlTableCellCollectionUse the HtmlTableCellCollection class to programmatically manage a collection of HtmlTableCell objects that represent the cells of a single row in an HtmlTable control. 此类通常用于添加、移除或修改HtmlTable控件的行中的单元格的内容。This class is commonly used to add, remove, or modify the contents of a cell in a row of an HtmlTable control.

备注

控件包含一个Rows 属性HtmlTableRow , 该属性包含对象的集合。 HtmlTableAn HtmlTable control contains a Rows property that contains a collection of HtmlTableRow objects. HtmlTableRow个对象都表示表中的单个行。Each HtmlTableRow object represents an individual row in the table. 对象包含一个Cells表示对象集合的HtmlTableCell属性。 HtmlTableRowAn HtmlTableRow object contains a Cells property that represents a collection of HtmlTableCell objects. 这些对象又表示行的单个单元格。These objects, in turn, represent the individual cells of a row. 若要检索单个单元格, 请首先HtmlTableRow获取表示表中包含该单元格的行的对象 ( Rows来自HtmlTable控件的集合)。To retrieve an individual cell, first get the HtmlTableRow object that represents the row containing the cell in the table (from the Rows collection of the HtmlTable control). 然后, 可以HtmlTableCell CellsHtmlTableRow对象的集合中获取代表行中的单元格的对象。You can then get the HtmlTableCell object that represents the cell in the row (from the Cells collection of the HtmlTableRow object).

属性

Count

获取 HtmlTableCellCollection 集合中的 HtmlTableCell 对象数。Gets the number of HtmlTableCell objects in the HtmlTableCellCollection collection.

IsReadOnly

获取指示 HtmlTableCellCollection 集合是否为只读的值。Gets a value indicating whether the HtmlTableCellCollection collection is read-only.

IsSynchronized

获取一个值,该值指示对 HtmlTableCellCollection 集合的访问是否同步(线程安全)。Gets a value indicating whether access to the HtmlTableCellCollection collection is synchronized (thread safe).

Item[Int32]

获取 HtmlTableCell 集合中指定索引处的 HtmlTableCellCollection 对象。Gets the HtmlTableCell object at the specified index from the HtmlTableCellCollection collection.

SyncRoot

获取可用于同步 HtmlTableCellCollection 集合访问的对象。Gets the object that can be used to synchronize access to the HtmlTableCellCollection collection.

方法

Add(HtmlTableCell)

将指定的 HtmlTableCell 对象追加到 HtmlTableCellCollection 集合的结尾。Appends the specified HtmlTableCell object to the end of the HtmlTableCellCollection collection.

Clear()

HtmlTableCellCollection 集合中移除所有 HtmlTableCell 对象。Removes all HtmlTableCell objects from the HtmlTableCellCollection collection.

CopyTo(Array, Int32)

HtmlTableCellCollection 中的指定索引开始,将 Array 集合中的项复制到指定的 ArrayCopies the items from the HtmlTableCellCollection collection to the specified Array, beginning with the specified index in the Array.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetEnumerator()

返回一个实现了 IEnumerator 的对象,其中包含 HtmlTableCell 集合内的所有 HtmlTableCellCollection 对象。Returns a IEnumerator-implemented object that contains all HtmlTableCell objects in the HtmlTableCellCollection collection.

GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
Insert(Int32, HtmlTableCell)

HtmlTableCell 集合的指定索引位置添加指定的 HtmlTableCellCollection 对象。Adds the specified HtmlTableCell object at the specified index location of the HtmlTableCellCollection collection.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
Remove(HtmlTableCell)

HtmlTableCell 集合中移除指定的 HtmlTableCellCollection 对象。Removes the specified HtmlTableCell object from the HtmlTableCellCollection collection.

RemoveAt(Int32)

移除 HtmlTableCell 集合中指定索引处的 HtmlTableCellCollection 对象。Removes the HtmlTableCell object at the specified index from the HtmlTableCellCollection collection.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

扩展方法

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于

另请参阅