HtmlTableCell 서버 컨트롤 선언 구문

업데이트: 2007년 11월

<td> 및 <th> HTML 요소에 매핑되는 서버측 컨트롤을 만들어 표의 셀을 조작할 수 있도록 합니다.

<td|th
    EnableViewState="False|True"
    Id="string"
    Visible="False|True"
    OnDataBinding="OnDataBinding event handler"
    OnDisposed="OnDisposed event handler"
    OnInit="OnInit event handler"
    OnLoad="OnLoad event handler"
    OnPreRender="OnPreRender event handler"
    OnUnload="OnUnload event handler"
    runat="server"
    >
CellContent
</td|/th>

설명

HtmlTableCell 클래스를 사용하여 <td> 및 <th> HTML 요소를 프로그래밍할 수 있습니다. <td> 요소는 데이터 셀을 나타내고 <th> 요소는 머리글 셀을 나타냅니다. <th> 셀의 내용은 항상 굵게 표시되고 가운데 정렬됩니다.

HtmlTableCell 클래스를 사용하면 각 개별 셀의 모양을 제어할 수 있습니다. BgColor, BorderColor, HeightWidth 속성을 설정하여 각각 셀의 배경색, 테두리 색, 높이 및 너비를 제어할 수 있습니다.

참고

같은 행에 있는 셀의 높이는 항상 같으며 열에서 가장 높은 셀에 다른 셀의 높이가 맞춰집니다.

셀 내용의 가로 및 세로 맞춤은 각각 AlignVAlign 속성을 설정하여 제어됩니다. 또한 NoWrap 속성을 설정하여 셀 내에서 텍스트가 자동으로 줄 바꿈되는지 여부를 지정할 수 있습니다.

HtmlTableCell 클래스를 사용하면 ColSpanRowSpan 속성을 설정하여 셀을 확장할 수 있습니다. ColSpan 속성을 사용하면 셀에 사용되는 열 수를 제어할 수 있으며 RowSpan 속성은 셀에 사용되는 행 수를 지정합니다.

참고

셀의 크기를 조정하기 위해서는 표에 있는 각 행의 길이가 같아야 하며 마찬가지로 각 열의 높이도 같아야 합니다. 그렇지 않으면 표가 올바르게 표시되지 않을 수 있습니다.

예제

다음 예제에서는 HtmlTableCell 개체를 사용하여 HtmlTable 컨트롤의 셀 내용을 수정하는 방법을 보여 줍니다.

<%@ Page Language="VB" AutoEventWireup="True" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >

<head>
<title>HtmlTableCell Control</title>

   <script runat="server">
       Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)

           Dim i As Integer
           Dim j As Integer

           ' Iterate through the rows of the table.
           For i = 0 To Table1.Rows.Count - 1

               ' Iterate through the cells of a row.       
               For j = 0 To Table1.Rows(i).Cells.Count - 1

                   ' Change the inner HTML of the cell.
                   Table1.Rows(i).Cells(j).InnerHtml = "Row " & i.ToString() _
                                                       & ", Column " & _
                                                     j.ToString()
               Next j
           Next i
       End Sub
   </script>

</head>
<body>
   <form id="Form1" runat="server">

      <h3>HtmlTableCell Example</h3>

      <table id="Table1" 
             style="border-width:1; border-color:Black"
             runat="server">

         <tr>
            <td>
               Cell 1
            </td>
            <td>
               Cell 2
            </td>
         </tr>
         <tr>
            <td>
               Cell 3
            </td>
            <td>
               Cell 4
            </td>
         </tr>

      </table>


      <br /><br />

      <input id="Button1" type="button" 
             value="Change Table Contents"
             onserverclick="Button_Click" 
             runat="server"/>

   </form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >

<head>
<title>HtmlTableCell Control</title>

   <script runat="server">
      void Button_Click(Object sender, EventArgs e) 
      {

         // Iterate through the rows of the table.
         for (int i=0; i<=Table1.Rows.Count - 1; i++)
         {

            // Iterate through the cells of a row.
            for (int j=0; j<=Table1.Rows[i].Cells.Count - 1; j++)
            {
               // Change the inner HTML of the cell.
               Table1.Rows[i].Cells[j].InnerHtml = "Row " + i.ToString() + 
                                                   ", Column " + 
                                                   j.ToString(); 
            }

         }

      }
   </script>

</head>
<body>

   <form id="Form1" runat="server">

      <h3>HtmlTableCell Example</h3>

      <table id="Table1" 
             style="border-width:1; border-color:Black"
             runat="server">

         <tr>
            <td>
               Cell 1
            </td>
            <td>
               Cell 2
            </td>
         </tr>
         <tr>
            <td>
               Cell 3
            </td>
            <td>
               Cell 4
            </td>
         </tr>

      </table>


      <br /><br />

      <input id="Button1" type="button" 
             value="Change Table Contents"
             onserverclick="Button_Click" 
             runat="server"/>

   </form>

</body>
</html>

참고 항목

참조

HtmlTableCell

HtmlTable

System.Web.UI.HtmlControls

기타 리소스

HTML 서버 컨트롤