다음을 통해 공유


Table.Rows 속성

정의

컨트롤의 행 Table 컬렉션을 가져옵니다.

public:
 virtual property System::Web::UI::WebControls::TableRowCollection ^ Rows { System::Web::UI::WebControls::TableRowCollection ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerDefaultProperty)]
public virtual System.Web.UI.WebControls.TableRowCollection Rows { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerDefaultProperty)>]
member this.Rows : System.Web.UI.WebControls.TableRowCollection
Public Overridable ReadOnly Property Rows As TableRowCollection

속성 값

TableRowCollection 컨트롤의 개체 TableTableRow 포함하는 A입니다.

특성

예제

다음 예제에서는 컬렉션을 사용하여 Rows 프로그래밍 방식으로 테이블을 생성하는 방법을 보여 줍니다. 테이블을 동적으로 만드는 작업은 세 단계로 구성됩니다. 먼저 행의 셀을 나타내는 개체를 만듭니 TableCell 다. 셀의 콘텐츠는 속성을 설정 Text 하거나 컨트롤을 컬렉션TableCell에 추가하여 추가됩니다Control.Controls. 다음으로 테이블의 TableRow 행을 나타내는 행을 만듭니다. TableCell 앞에서 만든 개체를 .의 컬렉션에 Cells 추가합니다TableRow. 마지막으로 컨트롤 컬렉션에 Rows 추가 TableRow 합니다Table. 테이블의 각 행에 대해 이 프로세스를 반복합니다.

메모

다음 코드 샘플에서는 단일 파일 코드 모델을 사용하며 코드 숨김 파일에 직접 복사한 경우 제대로 작동하지 않을 수 있습니다. 이 코드 샘플은 확장 an. aspx 있는 빈 텍스트 파일로 복사해야 합니다. Web Forms 코드 모델에 대한 자세한 내용은 ASP.NET Web Forms 페이지 코드 모델을 참조하세요.

<%@ 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">

    private void Page_Load(Object sender, EventArgs e)
    {
        // Generate rows and cells.           
        int numrows = 3;
        int numcells = 2;
        for (int j = 0; j < numrows; j++)
        {          
            TableRow r = new TableRow();
            for (int i = 0; i < numcells; i++) {
                TableCell c = new TableCell();
                c.Controls.Add(new LiteralControl("row " 
                    + j.ToString() + ", cell " + i.ToString()));
                r.Cells.Add(c);
            }
            Table1.Rows.Add(r);
        }
    }

</script>

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

    <h3>Table Example, constructed programmatically</h3>
    <asp:Table id="Table1" 
        GridLines="Both" 
        HorizontalAlign="Center" 
        Font-Names="Verdana" 
        Font-Size="8pt" 
        CellPadding="15" 
        CellSpacing="0" 
        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)
        ' Generate rows and cells.           
        Dim numrows As Integer = 3
        Dim numcells As Integer = 2
        Dim j As Integer
        For j = 0 To numrows - 1
            Dim r As New TableRow()
            Dim i As Integer
            For i = 0 To numcells - 1
                Dim c As New TableCell()
                c.Controls.Add(New LiteralControl("row " & j.ToString() & ", cell " & i.ToString()))
                r.Cells.Add(c)
            Next i
            Table1.Rows.Add(r)
        Next j
    End Sub 'Page_Load
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Programmatic Table Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <h3>Table Example, constructed programmatically</h3>
    <asp:Table id="Table1" 
        GridLines="Both" 
        HorizontalAlign="Center" 
        Font-Names="Verdana" 
        Font-Size="8pt" 
        CellPadding="15" 
        CellSpacing="0" 
        Runat="server"/>

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

설명

Rows 컬렉션을 사용하여 컨트롤의 개체 TableTableRow 프로그래밍 방식으로 관리합니다. A TableRow 는 테이블의 행을 나타냅니다.

메모

이 속성은 일반적으로 프로그래밍 방식으로 테이블을 작성할 때만 사용됩니다. 디자인 타임에는 컨트롤의 Table 여는 태그와 닫는 태그 사이에 개체를 선언하여 TableRow 설정합니다.

적용 대상

추가 정보