共用方式為


TableRowCollection.AddAt(Int32, TableRow) 方法

定義

將指定的 TableRow 物件加入在指定索引位置的 TableRowCollection

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

參數

index
Int32

TableRowCollection 中要加入 TableRow 的位置。

row
TableRow

要加入 TableRowCollectionTableRow 物件。

範例

下列範例示範如何將 物件新增 TableRow 至的 TableRowCollection中間。 請注意,在範例中, RowsTable 屬性是 類別的 TableRowCollection 實例。

<%@ 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 = 4;
        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 a row in the middle of the table.
        TableRow new_rw = new TableRow();
        Table1.Rows.AddAt(numRows / 2, new_rw);

        for (int cellNum = 0; cellNum < numCells; cellNum++)
        {
            TableCell cel = new TableCell();
            cel.Text = "Mid";
            Table1.Rows[numRows / 2].Cells.AddAt(cellNum, cel);
            counter++;
        }
    }
</script>
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Programmatic Table</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h3>Programmatic Table 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(ByVal sender As Object, ByVal e As EventArgs)
            
        Dim numRows As Integer = 4
        Dim numCells As Integer = 6
        Dim counter As Integer = 1
        Dim cellNum As Integer

        ' Generate a basic table.         
        Dim rowNum As Integer
        For rowNum = 0 To numRows - 1
            Dim rw As New TableRow()
            For cellNum = 0 To numCells - 1
                Dim cel As New TableCell()
                cel.Text = counter.ToString()
                counter += 1
                rw.Cells.Add(cel)
            Next cellNum
            Table1.Rows.Add(rw)
        Next rowNum
            
        ' Add a row in the middle of the table.
        Dim new_rw As New TableRow()
        Table1.Rows.AddAt(numRows / 2, new_rw)
            
        For cellNum = 0 To numCells - 1
            Dim cel As New TableCell()
            cel.Text = "Mid"
            Table1.Rows((numRows / 2)).Cells.AddAt(cellNum, cel)
            counter += 1
        Next cellNum
    End Sub
</script>

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

備註

使用這個方法,在指定的索引處插入TableRowTableRowCollection指定的 。

適用於

另請參閱