HtmlTableRow.Align Property

 

Gets or sets the horizontal alignment of the content in the cells of a row in an HtmlTable control.

Namespace:   System.Web.UI.HtmlControls
Assembly:  System.Web (in System.Web.dll)

public string Align { get; set; }

Property Value

Type: System.String

The horizontal alignment of the content in the cells of a row in an HtmlTable control. The default value is String.Empty, which indicates that this property is not set.

Use the Align property to specify the horizontal alignment of the content in the cells of a row in an HtmlTable control.

System_CAPS_noteNote

Setting this property affects all cells in a row of a table represented by an instance of the HtmlTableRow class. To apply an alignment attribute to a single cell of a row, set the Align property for that cell.

The following table lists the values that can be used for this property.

Value

Description

Left

Aligns the contents of the cell with the left edge of the cell.

Center

Aligns the contents of the cell in the middle of the cell.

Right

Aligns the contents of the cell with the right edge of the cell.

System_CAPS_noteNote

You can also use Justify and Char as values for this property. However, not all browsers support these features.

The following example demonstrates how to use the Align property to control the horizontal alignment of the contents of the cells in an entire row.

<%@ 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">
<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++)
    {

      // Update the properties of each row. 
      Table1.Rows[i].Align = AlignSelect.Value;
      Table1.Rows[i].VAlign = VAlignSelect.Value;

    }

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>HtmlTableRow Example</title>
</head>
<body>

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

      <h3>HtmlTableRow Example</h3>

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

         <tr>
            <td>
               Here is some content for Cell 1.
            </td>
            <td>
               Here is some content for Cell 2.
            </td>
         </tr>
         <tr>
            <td style="width:100; height:100">
               Here is some content for Cell 3.
            </td>
            <td style="width:100; height:100">
               Here is some content for Cell 4.
            </td>
         </tr>

      </table>

      <hr />

      Select the display settings for the cells in the table: <br /><br />

      Align:
      <select id="AlignSelect" 
              runat="server">

         <option value="Left" selected="selected">Left</option>
         <option value="Center">Center</option>
         <option value="Right">Right</option>

      </select>

      &nbsp;&nbsp;

      VAlign:
      <select id="VAlignSelect" 
              runat="server">

         <option value="Top">Top</option>
         <option value="Middle" selected="selected">Middle</option>
         <option value="Bottom">Bottom</option>

      </select>

      <br /><br />

      <input type="button" 
             value="Generate Table"
             onserverclick="Button_Click" 
             runat="server"/>

   </form>

</body>
</html>

.NET Framework
Available since 1.1
Return to top
Show: