Export (0) Print
Expand All

HtmlTableRow Class

Represents the <tr> HTML element in an HtmlTable control.

For a list of all members of this type, see HtmlTableRow Members.

System.Object
   System.Web.UI.Control
      System.Web.UI.HtmlControls.HtmlControl
         System.Web.UI.HtmlControls.HtmlContainerControl
            System.Web.UI.HtmlControls.HtmlTableRow

[Visual Basic]
Public Class HtmlTableRow
   Inherits HtmlContainerControl
[C#]
public class HtmlTableRow : HtmlContainerControl
[C++]
public __gc class HtmlTableRow : public HtmlContainerControl
[JScript]
public class HtmlTableRow extends HtmlContainerControl

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

The <tr> element represents a row in a table. Use the HtmlTableRow class to programmatically control the <tr> HTML elements in an HtmlTable control.

The HtmlTableRow class allows you to customize the appearance of a row in a table by specifying the background color, the border color, and the height of the cells in the row. These attributes are set using the BgColor, BorderColor, and Height properties.

You can control the alignment of the contents in the cells for the entire row by using the Align and VAlign properties. The Align property controls the horizontal alignment of the contents of the cells, while the VAlign property controls the vertical alignment.

By using the Cells collection of this class, you can programmatically access the individual cells in a row of a table. This allows you to control the properties of each cell, as well as the content.

For a list of initial property values for an instance of HtmlTableRow, see the HtmlTableRow constructor.

Example

[Visual Basic, C#, JScript] The following example demonstrates how to use an HtmlTableRow to represent a row in the HtmlTable control. An HtmlTableRow is retrieved from the Rows collection of the table to modify its contents.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
<head>

   <script runat="server">

      Sub Button_Click(sender As Object, 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 runat="server">

      <h3>HtmlTableRow Example</h3>

      <table id="Table1" 
             Border="1" 
             BorderColor="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 type="button" 
             value="Change Table Contents"
             OnServerClick = "Button_Click" 
             runat="server"/>

   </form>

</body>
</html>

[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>

<html>
<head>

   <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 runat="server">

      <h3>HtmlTableRow Example</h3>

      <table id="Table1" 
             Border="1" 
             BorderColor="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 type="button" 
             value="Change Table Contents"
             OnServerClick = "Button_Click" 
             runat="server"/>

   </form>

</body>
</html>

[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>

<html>
<head>

   <script runat="server">

      function Button_Click(sender, e : EventArgs) 
      {

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

            // Iterate through the cells of a row.
            for (var j : int =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 runat="server">

      <h3>HtmlTableRow Example</h3>

      <table id="Table1" 
             Border="1" 
             BorderColor="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 type="button" 
             value="Change Table Contents"
             OnServerClick = "Button_Click" 
             runat="server"/>

   </form>

</body>
</html>

[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Web.UI.HtmlControls

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Web (in System.Web.dll)

See Also

HtmlTableRow Members | System.Web.UI.HtmlControls Namespace | HtmlTable | HtmlTableRowCollection | BgColor | BorderColor | Height | Align | VAlign | Cells

Show:
© 2015 Microsoft