TableCellCollection.AddAt Method (Int32, TableCell)

 
System_CAPS_noteNote

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

Adds the specified TableCell to the TableCellCollection at the specified index location.

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

public void AddAt(
	int index,
	TableCell cell
)

Parameters

index
Type: System.Int32

The location in the TableCellCollection at which to add the TableCell.

cell
Type: System.Web.UI.WebControls.TableCell

The TableCell to add to the TableCellCollection.

Use this method to insert the specified TableCell in a TableCellCollection at the specified index.

The following example demonstrates how to use the AddAt method to add a TableCell to the middle of 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" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

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

        // Generate a basic table.         
        for (int rowNum = 0; rowNum < numrows; rowNum++) 
        {          
            TableRow rw = new TableRow();
            for (int cellNum = 0; cellNum < numcells; cellNum++) 
            {
                TableCell cel = new TableCell();
                cel.Text=counter.ToString();
                counter++;
                rw.Cells.Add(cel);
            }
             Table1.Rows.Add(rw);
         }

         // Add cells in the middle of the table. 
         for (int rowNum = 0; rowNum <numrows; rowNum++) 
         {            
             TableCell cel = new TableCell();
             cel.Text="Mid";
             Table1.Rows[rowNum].Cells.AddAt(numcells / 2, cel);
             counter++;
         }
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>TableCellCollection Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

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

    </div>
    </form>
</body>
</html>

.NET Framework
Available since 1.1
Return to top
Show: