TableCellCollection.AddAt(Int32, TableCell) 方法

定义

将指定的 TableCell 添加到 TableCellCollection 中的指定索引位置。

public:
 void AddAt(int index, System::Web::UI::WebControls::TableCell ^ cell);
public void AddAt (int index, System.Web.UI.WebControls.TableCell cell);
member this.AddAt : int * System.Web.UI.WebControls.TableCell -> unit
Public Sub AddAt (index As Integer, cell As TableCell)

参数

index
Int32

TableCellCollection 添加到 TableCell 中的位置。

cell
TableCell

要添加到 TableCellTableCellCollection

示例

以下示例演示如何使用 AddAt 方法将 添加到 TableCell 的中间 TableCellCollection。 请注意,在示例中, CellsTableRow 属性是 类的 TableCellCollection 实例。

<%@ 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>
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Sub Page_Load(sender As Object, e As EventArgs)
        Dim numrows As Integer = 5
        Dim numcells As Integer = 6
        Dim counter As Integer = 1

        ' Generate a basic table.         
        Dim rowNum As Integer
        For rowNum = 0 To numrows - 1
            Dim rw As New TableRow()
            Dim cellNum As Integer
            For cellNum = 0 To numcells - 1
                Dim cel As New TableCell()
                cel.Text = counter.ToString()
                counter += 1
                rw.Cells.Add(cel)
            Next
            Table1.Rows.Add(rw)
        Next

        ' Add cells in the middle of the table. 
        For rowNum = 0 To numrows - 1
            Dim cel As New TableCell()
            cel.Text = "Mid"
            Table1.Rows(rowNum).Cells.AddAt(numcells / 2, cel)
            counter += 1
        Next
    End Sub
 
</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>

注解

使用此方法在指定的 TableCell 索引处 TableCellCollection 插入指定的 。

适用于

另请参阅