共用方式為


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 方法,將陣列中的物件新增 TableCellTableCellCollection。 請注意,在範例中, 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 至集合。

適用於

另請參閱