Share via


Sintaxe declarativa do controle de servidor de HtmlTableRow

Cria um controle de servidor que mapeia para o <tr> elemento HTML e permite que você crie e manipule uma linha na tabela.

<tr 
    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"
    >
 
   <td>cellcontent</td> 
   <td>cellcontent</td> 
   <td>cellcontent</td> 
 
</tr>

Comentários

Use o HtmlTableRow classe para programar para o <tr> elemento HTML. A <tr> elemento representa uma linha na tabela.

O HtmlTableRow classe lhe permite controlar a aparência de cada linha individual na tabela. Você pode controlar a cor de plano de fundo, a cor da borda e a altura da linha, definindo a BgColor, BorderColor, e Height Propriedades, respectivamente.

O alinhamento horizontal e vertical do conteúdo das células na linha são controlados pela configuração de Align e VAlign Propriedades, respectivamente.

Cada linha na tabela contém um Cells coleção que contém um HtmlTableCell para cada célula na linha.

Exemplo

O exemplo a seguir demonstra como usar um HtmlTableCell 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>HtmlTableRow 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" runat="server" 
                style="border-width: 1; border-color: Black">

         <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>HtmlTableRow 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" runat="server" 
                style="border-width: 1; border-color: Black">

         <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

HtmlTableRow

Sintaxe declarativa do controle de servidor de HtmlTableCell

Sintaxe declarativa do controle de servidor de HtmlTable

System.Web.UI.HtmlControls

Outros recursos

HTML Server Controls