TableCellCollection.AddRange(TableCell[]) Metoda

Definicja

TableCell Dołącza obiekty z określonej tablicy do końca kolekcji.

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())

Parametry

cells
TableCell[]

Tablica zawierająca TableCell obiekty do dodania do kolekcji.

Wyjątki

Wartość parametru cells to null.

Przykłady

W poniższym przykładzie pokazano, jak za pomocą AddRange metody dodać TableCell obiekty z tablicy do obiektu TableCellCollection. Należy pamiętać, Cells że w przykładzie właściwość TableRow klasy jest wystąpieniem TableCellCollection klasy.

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

Uwagi

AddRange Użyj metody , aby dołączyć TableCell obiekty z określonej tablicy do kolekcji. Ta metoda jest często używana podczas tworzenia wiersza tabeli. Aby utworzyć wiersz tabeli, najpierw utwórz tablicę TableCell obiektów reprezentujących komórki wiersza. Następnie użyj AddRange metody , przekazując tablicę jako argument, aby dodać TableCell obiekty do kolekcji.

Dotyczy

Zobacz też