Udostępnij za pośrednictwem


TableRow.CellControlCollection.Add(Control) Metoda

Definicja

Dodaje określony Control obiekt do kolekcji TableRow.CellControlCollection .

public:
 override void Add(System::Web::UI::Control ^ child);
public override void Add(System.Web.UI.Control child);
override this.Add : System.Web.UI.Control -> unit
Public Overrides Sub Add (child As Control)

Parametry

child
Control

Element Control do dodania do elementu TableRow.CellControlCollection.

Wyjątki

Dodany Control element musi mieć typ TableCell.

Przykłady

W poniższym przykładzie kodu pokazano, jak utworzyć tabelę, dodać elementy do tabeli programowo, a następnie wyświetlić tabelę na stronie sieci Web. Zwróć uwagę, Cells jak właściwość kontrolki TableRow reprezentuje TableRow.CellControlCollection kolekcję i sposób Add użycia metody do dodawania komórek do wiersza.

Ten przykład kodu jest częścią większego przykładu udostępnionego dla klasy TableRow.

// Create more rows for the table.
for (int rowNum = 2; rowNum < 10; rowNum++)
{
    TableRow tempRow = new TableRow();
    for (int cellNum = 0; cellNum < 3; cellNum++)
    {
        TableCell tempCell = new TableCell();
        tempCell.Text = 
            String.Format("({0},{1})", rowNum, cellNum);
        tempRow.Cells.Add(tempCell);
    }
    Table1.Rows.Add(tempRow);
}
' Create more rows for the table.
Dim rowNum As Integer
For rowNum = 2 To 9
    Dim tempRow As New TableRow()
    Dim cellNum As Integer
    For cellNum = 0 To 2
        Dim tempCell As New TableCell()
        tempCell.Text = _
            String.Format("({0},{1})", rowNum, cellNum)
        tempRow.Cells.Add(tempCell)
    Next
    Table1.Rows.Add(tempRow)
Next

Uwagi

Dodana kontrolka może być tylko obiektem TableCell ; w przeciwnym razie ArgumentException zgłaszany jest element .

Dotyczy

Zobacz też