TableCellCollection.Add Method (TableCell)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Appends the specified TableCell to the end of the TableCellCollection.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public int Add(
	TableCell cell


Type: System.Web.UI.WebControls.TableCell

The TableCell to add to the collection.

Return Value

Type: System.Int32

The index number of the TableCell.

Use this method to add the specified TableCell to the end of a TableCellCollection.

The following example demonstrates how to use the Add method to add a TableCell to a TableCellCollection. Note that in the example, the Cells property of the TableRow is an instance of the TableCellCollection class.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

<script runat="server">

    void Page_Load(Object sender, EventArgs e) 
        int numrows = 5;
        int numcells = 6;
        int counter = 1;

        // Create a table.
        for (int rowNum = 0; rowNum < numrows; rowNum++) 
             TableRow rw = new TableRow();
             for (int cellNum = 0; cellNum < numcells; cellNum++) 
                 TableCell cel = new TableCell();


<html xmlns="" >
<head runat="server">
    <title>TableCellCollection Example</title>
    <form id="form1" runat="server">

    <h3>TableCellCollection Example</h3>
    <asp:Table id="Table1" runat="server"/>


.NET Framework
Available since 1.1
Return to top