Share via


TableCell 웹 서버 컨트롤 선언 구문

업데이트: 2007년 11월

Table 컨트롤에 셀을 나타내고 프로그래밍 방식으로 조작하는 데 사용할 수 있습니다.

<asp:TableCell
    AccessKey="string"
    AssociatedHeaderCellID="string"
    BackColor="color name|#dddddd"
    BorderColor="color name|#dddddd"
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
        Inset|Outset"
    BorderWidth="size"
    ColumnSpan="integer"
    CssClass="string"
    Enabled="True|False"
    EnableTheming="True|False"
    EnableViewState="True|False"
    Font-Bold="True|False"
    Font-Italic="True|False"
    Font-Names="string"
    Font-Overline="True|False"
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
        Large|X-Large|XX-Large"
    Font-Strikeout="True|False"
    Font-Underline="True|False"
    ForeColor="color name|#dddddd"
    Height="size"
    HorizontalAlign="NotSet|Left|Center|Right|Justify"
    ID="string"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    RowSpan="integer"
    runat="server"
    SkinID="string"
    Style="string"
    TabIndex="integer"
    Text="string"
    ToolTip="string"
    VerticalAlign="NotSet|Top|Middle|Bottom"
    Visible="True|False"
    Width="size"
    Wrap="True|False"
/></asp:TableCell>

설명

TableCell 클래스의 인스턴스는 Table 컨트롤에서 셀을 나타냅니다. 각 행의 셀은 행을 나타내는 TableRow의 Cells 컬렉션에 저장됩니다. Text 속성을 사용하여 셀 내용을 조작할 수 있습니다.

이 클래스를 사용하면 셀의 내용을 표시하는 방법을 제어할 수 있습니다. HorizontalAlignVerticalAlign 속성을 설정하면 셀 내용을 각각 가로 맞춤과 세로 맞춤으로 지정할 수 있습니다. 셀 내용이 셀 길이보다 길 때 자동으로 다음 줄로 넘어갈지 여부를 지정하려면 Wrap 속성을 사용하면 됩니다.

Table 컨트롤에서 셀이 사용하는 행 또는 열의 수를 지정할 수도 있습니다. RowSpanColumnSpan 속성은 각각 셀에 사용되는 행과 열의 수를 제어합니다.

경고

텍스트는 TableCell 컨트롤에 표시된 후에 HTML로 인코딩됩니다. 따라서 텍스트의 HTML 태그 내에 스크립트를 포함시킬 수 있습니다. 컨트롤 값을 사용자 입력에서 가져온 경우 값이 유효한지 확인하여 보안상의 허점을 방지합니다.

TableCell 웹 서버 컨트롤의 속성과 이벤트에 대한 자세한 내용은 TableCell 클래스 설명서를 참조하십시오.

예제

다음 코드 예제에서는 표를 만들고, 프로그래밍 방식으로 표에 요소를 추가한 다음, 웹 페이지에 표를 표시하는 방법을 보여 줍니다. 이때 TableCell 컨트롤을 인스턴스화하고 해당 컨트롤의 속성 값을 설정하는 방법에 주목하십시오.

<%@ page language="VB" %>
<%@ Import Namespace="System.Drawing" %>

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

<script runat="server">
    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        ' Create a TableItemStyle object that can be
        ' set as the default style for all cells
        ' in the table.
        Dim tableStyle As New TableItemStyle()
        tableStyle.HorizontalAlign = HorizontalAlign.Center
        tableStyle.VerticalAlign = VerticalAlign.Middle
        tableStyle.Width = Unit.Pixel(100)
        ' Create more rows for the table.
        Dim rowNum As Integer
        For rowNum = 2 To 9
            Dim tempRow As New TableRow()
            Dim cellNum As Integer
            For cellNum = 0 To 2
                Dim tempCell As New TableCell()
                tempCell.Text = _
                    String.Format("({0},{1})", rowNum, cellNum)
                tempRow.Cells.Add(tempCell)
            Next
            Table1.Rows.Add(tempRow)
        Next

        ' Apply the TableItemStyle to all rows in the table.
        Dim rw As TableRow
        For Each rw In Table1.Rows
            Dim cel As TableCell
            For Each cel In rw.Cells
                cel.ApplyStyle(tableStyle)
            Next
        Next

        ' Create a header for the table.
        Dim header As New TableHeaderCell()
        header.RowSpan = 1
        header.ColumnSpan = 3
        header.Text = "Table of (x,y) Values"
        header.Font.Bold = True
        header.BackColor = Color.Gray
        header.HorizontalAlign = HorizontalAlign.Center
        header.VerticalAlign = VerticalAlign.Middle

        ' Add the header to a new row.
        Dim headerRow As New TableRow()
        headerRow.Cells.Add(header)

        ' Add the header row to the table.
        Table1.Rows.AddAt(0, headerRow)
    End Sub
</script>

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

    <h1>TableCell Example</h1>
    <asp:table id="Table1" runat="server" 
        CellPadding="3" CellSpacing="3"
        Gridlines="both">
        <asp:TableRow>
            <asp:TableCell Text="(0,0)" />
            <asp:TableCell Text="(0,1)" />
            <asp:TableCell Text="(0,2)" />
        </asp:TableRow>
        <asp:TableRow>
            <asp:TableCell Text="(1,0)" />
            <asp:TableCell Text="(1,1)" />
            <asp:TableCell Text="(1,2)" />
        </asp:TableRow>
    </asp:table>

    </div>
    </form>
  </body>
</html>
<%@ page language="C#" %>
<%@ Import Namespace="System.Drawing" %>

<!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, System.EventArgs e)
    {
        // Create a TableItemStyle object that can be
        // set as the default style for all cells
        // in the table.
        TableItemStyle tableStyle = new TableItemStyle();
        tableStyle.HorizontalAlign = HorizontalAlign.Center;
        tableStyle.VerticalAlign = VerticalAlign.Middle;
        tableStyle.Width = Unit.Pixel(100);

        // Create more rows for the table.
        for (int rowNum = 2; rowNum < 10; rowNum++)
        {
            TableRow tempRow = new TableRow();
            for (int cellNum = 0; cellNum < 3; cellNum++)
            {
                TableCell tempCell = new TableCell();
                tempCell.Text = 
                    String.Format("({0},{1})", rowNum, cellNum);
                tempRow.Cells.Add(tempCell);
            }
            Table1.Rows.Add(tempRow);
        }

        // Apply the TableItemStyle to all rows in the table.
        foreach (TableRow rw in Table1.Rows)
            foreach (TableCell cel in rw.Cells)
                cel.ApplyStyle(tableStyle);

        // Create a header for the table.
        TableHeaderCell header = new TableHeaderCell();
        header.RowSpan = 1;
        header.ColumnSpan = 3;
        header.Text = "Table of (x,y) Values";
        header.Font.Bold = true;
        header.BackColor = Color.Gray;
        header.HorizontalAlign = HorizontalAlign.Center;
        header.VerticalAlign = VerticalAlign.Middle;

        // Add the header to a new row.
        TableRow headerRow = new TableRow();
        headerRow.Cells.Add(header);

        // Add the header row to the table.
        Table1.Rows.AddAt(0, headerRow);  
    }
</script>

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

    <h1>TableCell Example</h1>
    <asp:table id="Table1" runat="server" 
        CellPadding="3" CellSpacing="3"
        Gridlines="both">
        <asp:TableRow>
            <asp:TableCell Text="(0,0)" />
            <asp:TableCell Text="(0,1)" />
            <asp:TableCell Text="(0,2)" />
        </asp:TableRow>
        <asp:TableRow>
            <asp:TableCell Text="(1,0)" />
            <asp:TableCell Text="(1,1)" />
            <asp:TableCell Text="(1,2)" />
        </asp:TableRow>
    </asp:table>

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

참고 항목

참조

TableCell

기타 리소스

웹 서버 컨트롤 구문