Sintaxis declarativa del control de servidor HtmlTableRow

Actualización: noviembre 2007

Crea un control del servidor que se asigna al elemento HTML <tr> y permite crear y manipular una fila en una tabla.

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

Comentarios

La clase HtmlTableRow se utiliza para programar basándose en el elemento HTML <tr> . Un elemento <tr> representa una fila de la tabla.

La clase HtmlTableRow permite controlar el aspecto de cada fila individual de la tabla. Puede controlar el color de fondo, el color de borde y el alto de la fila. Para ello, establezca las propiedades BgColor, BorderColor y Height, respectivamente.

La alineación horizontal y vertical del contenido de las celdas de la fila se controla mediante las propiedades Align y VAlign, respectivamente.

Cada fila de la tabla contiene una colección Cells que, a su vez, contiene un HtmlTableCell para cada celda de la fila.

Ejemplo

En el ejemplo siguiente se muestra cómo utilizar un HtmlTableCell para modificar el contenido de una celda en el control 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>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>

Vea también

Referencia

HtmlTableRow

Sintaxis declarativa del control de servidor HtmlTableCell

Sintaxis declarativa del control de servidor HtmlTable

System.Web.UI.HtmlControls

Otros recursos

Controles de servidor HTML