다음을 통해 공유


TableCellCollection.Add(TableCell) 메서드

정의

지정된 TableCellTableCellCollection 끝에 추가합니다.

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

매개 변수

cell
TableCell

컬렉션에 추가할 TableCell입니다.

반환

TableCell의 인덱스 번호를 반환합니다.

예제

다음 예제에 사용 하는 방법을 보여 줍니다.는 Add 메서드를 추가 TableCellTableCellCollection합니다. 예제에서 의 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;

        // 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();
                 cel.Text=counter.ToString();
                 counter++;
                 rw.Cells.Add(cel);
             }
             Table1.Rows.Add(rw);
        }
    }
 
</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
            
        ' Create a 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
    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.

적용 대상

추가 정보