TableRowCollection.Add(TableRow) Metodo

Definizione

Aggiunge l'oggetto TableRow specificato alla fine di TableRowCollection.

public:
 int Add(System::Web::UI::WebControls::TableRow ^ row);
public int Add (System.Web.UI.WebControls.TableRow row);
member this.Add : System.Web.UI.WebControls.TableRow -> int
Public Function Add (row As TableRow) As Integer

Parametri

row
TableRow

Oggetto TableRow da aggiungere alla classe TableRowCollection.

Restituisce

Int32

Indice dell'oggetto TableRow.

Esempio

Nell'esempio seguente viene illustrato come utilizzare il Add metodo per aggiungere un TableRow oggetto a un oggetto TableRowCollection. Si noti che nell'esempio la Rows proprietà di Table è un'istanza della TableRowCollection classe .

<%@ 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)
    {
        // Generate rows and cells.           
        int numRows = 5;
        int numCells = 6;
    int counter = 1;

        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();
                rw.Cells.Add(cel);
                counter++;
            }
            Table1.Rows.Add(rw);
            Table1.GridLines = GridLines.Both;
            Table1.CellPadding = 4;
            Table1.CellSpacing = 0;
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Programmatic Table</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h3>Table Example, constructed programmatically</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)
        ' Generate rows and cells.           
        Dim numRows As Integer = 5
        Dim numcells As Integer = 6
        Dim rowNum As Integer = 0
        Dim counter As Integer = 1

        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()
                rw.Cells.Add(cel)
            Next cellNum
            Table1.Rows.Add(rw)
        Next rowNum
        Table1.GridLines = GridLines.Both
        Table1.CellPadding = 4
        Table1.CellSpacing = 0
    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>Table Example, constructed programmatically</h3>
        <asp:Table id="Table1" runat="server"/>
    </div>
    </form>
</body>
</html>

Commenti

Utilizzare questo metodo per aggiungere un TableRow oggetto alla fine di un oggetto TableRowCollection.

Si applica a

Vedi anche