TableCellCollection.AddRange(TableCell[]) 方法

定义

TableCell 对象从指定的数组追加到集合的末尾。

public:
 void AddRange(cli::array <System::Web::UI::WebControls::TableCell ^> ^ cells);
public void AddRange (System.Web.UI.WebControls.TableCell[] cells);
member this.AddRange : System.Web.UI.WebControls.TableCell[] -> unit
Public Sub AddRange (cells As TableCell())

参数

cells
TableCell[]

该数组包含 TableCell 对象,这些对象将要添加到集合中。

例外

cells 参数的值为 null

示例

下面的示例演示如何使用 AddRange 方法将 数组中的 TableCell 对象添加到 TableCellCollection。 请注意,在示例中, CellsTableRow 属性是 类的 TableCellCollection 实例。

void Page_Load(Object sender, EventArgs e) 
{
    int numRows = 3;
    int numCells = 2;
    // Create 3 rows, each containing 2 cells.
    for(int rowNum = 0; rowNum < numRows; rowNum++) 
    {
        TableCell[] arrayOfTableRowCells = 
            new TableCell[numCells];
        TableRow tRow =  new TableRow();

        for (int cellNum = 0; cellNum < numCells; cellNum++)
        {
            TableCell tCell =  new TableCell();
            tCell.Text = 
                String.Format("[Row {0}, Cell {1}]", 
                    rowNum, cellNum);
            arrayOfTableRowCells[cellNum] = tCell;
        } 

        // Get 'TableCellCollection' associated 
        // with the 'TableRow'.
        TableCellCollection myTableCellCol = tRow.Cells;
        // Add a row of cells. 
        myTableCellCol.AddRange(arrayOfTableRowCells);
        Table1.Rows.Add(tRow);
    } 
}
Sub Page_Load(ByVal sender As Object, _
    ByVal e As EventArgs)

    Dim numRows As Integer = 3
    Dim numCells As Integer = 2
    ' Create 3 rows, each containing 2 cells.
    Dim rowNum As Integer
    For rowNum = 0 To numRows - 1
        Dim arrayOfTableRowCells(numCells - 1) As TableCell
        Dim rw As New TableRow()
        Dim cellNum As Integer
        For cellNum = 0 To numCells - 1
            Dim cel As New TableCell()
            cel.Text = _
                String.Format("[Row {0}, Cell {1}]", rowNum, cellNum)
            arrayOfTableRowCells(cellNum) = cel
        Next

        ' Get 'TableCellCollection' associated with the 'TableRow'.
        Dim myTableCellCol As TableCellCollection = rw.Cells
        ' Add a row of cells. 
        myTableCellCol.AddRange(arrayOfTableRowCells)
        Table1.Rows.Add(rw)
    Next
End Sub

注解

AddRange使用 方法将指定数组中的 TableCell 对象追加到集合中。 构造表的行时,通常使用此方法。 若要构造表的行,请先创建对象的数组 TableCell 来表示该行的单元格。 接下来,使用 AddRange 方法(将数组作为参数传递)将 TableCell 对象添加到集合中。

适用于

另请参阅