Share via


Sintaxe declarativa do controle de servidor de HtmlTableCell

Cria um controle de servidor que mapeia para o <td> e <th> elementos HTML e permite a você manipular uma célula em uma tabela.

<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>

Comentários

Use o HtmlTableCell classe para programar para o <td> e <th> elementos HTML. A <td> elemento representa uma célula de dados, enquanto o <th> elemento representa uma célula de cabeçalho. Observe que o conteúdo de um <th> célula estão sempre em negrito e centralizado.

O HtmlTableCell classe lhe permite controlar a aparência de cada célula individual. Você pode controlar a cor de plano de fundo, a cor da borda, a altura e a largura da célula, definindo a BgColor, BorderColor, Height, e Width Propriedades respectivamente.

Observação

Todas as células na mesma linha compartilham a mesma altura.A célula mais alta em uma linha determina a altura de todas as células na linha.

O alinhamento horizontal e vertical do conteúdo da célula são controlados pela configuração de Align e VAlign Propriedades, respectivamente. Você também pode especificar se o texto continua automaticamente na próxima linha da célula, definindo a NoWrap propriedade.

O HtmlTableCell classe permite que você estenda a células, definindo a ColSpan e RowSpan Propriedades. O ColSpan propriedade lhe permite controlar quantas colunas uma célula ocupa, enquanto o RowSpan propriedade especifica o número de linhas em uma célula ocupa.

Observação

Quando a abrangência de células, certifique-se de que cada linha da tabela é o mesmo comprimento.Além disso, certifique-se de que cada coluna é a mesma altura.Caso contrário, a tabela pode não apresentar conforme o esperado.

Exemplo

O exemplo a seguir demonstra como usar um HtmlTableCell o objeto para modificar o conteúdo de uma célula na HtmlTable de controle.

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

Consulte também

Referência

HtmlTableCell

HtmlTable

System.Web.UI.HtmlControls

Outros recursos

HTML Server Controls