Align Property
Collapse the table of content
Expand the table of content

HtmlTableCell.Align Property

Gets or sets the horizontal alignment of the content in the cell represented by an instance of the HtmlTableCell class.

[Visual Basic]
Public Property Align As String
[C#]
public string Align {get; set;}
[C++]
public: __property String* get_Align();
public: __property void set_Align(String*);
[JScript]
public function get Align() : String;
public function set Align(String);

Property Value

The horizontal alignment of the content in the cell represented by an instance of the HtmlTableCell class. The default value is String.Empty, which indicates that this property is not set.

Remarks

Use the Align property to specify the horizontal alignment of the content in a cell represented by an instance of the HtmlTableCell class.

Note   Setting this property affects only the cell represented by an instance of the HtmlTableCell class. To apply the same alignment to the cells of an entire row in the table, set the Align property of the row represented by an instance of the HtmlTableRow class.

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

Value Description
Left Aligns the contents of a cell with the left edge of the cell.
Center Aligns the contents of a cell in the middle of the cell.
Right Aligns the contents of a cell with the right edge of the cell.
Note   You can also use Justify and Char as values for this property, however not all browsers support these features.

Example

[Visual Basic, C#] The following example demonstrates how to use the Align property to programmatically control the alignment of the contents of the cells in an HtmlTable control.

[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
           
               ' Update the properties of each cell. 
               Table1.Rows(i).Cells(j).Align = AlignSelect.Value 
               Table1.Rows(i).Cells(j).NoWrap = Convert.ToBoolean(NoWrapSelect.Value)
               Table1.Rows(i).Cells(j).VAlign = VAlignSelect.Value

            Next j

         Next i

      End Sub

   </script>

</head>
<body>

   <form runat="server">

      <h3>HtmlTableCell Example</h3>

      <table id="Table1" 
             Border="1" 
             BorderColor="black" 
             runat="server">

         <tr>
            <td>
               Here's some content for Cell 1.
            </td>
            <td>
               Here's some content for Cell 2.
            </td>
         </tr>
         <tr>
            <td Width="100" Height="100">
               Here's some content for Cell 3.
            </td>
            <td Width="100" Height="100">
               Here's 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="True">Left</option>
         <option Value="Center">Center</option>
         <option Value="Right">Right</option>
        
      </select>

      &nbsp;&nbsp;

      NoWrap:
      <select id="NoWrapSelect" 
              runat="server">

         <option Value="true">True</option>
         <option Value="false" Selected="True">False</option>

      </select>

      &nbsp;&nbsp;

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

         <option Value="Top">Top</option>
         <option Value="Middle" Selected="True">Middle</option>
         <option Value="Bottom">Bottom</option>

      </select>
       
      <br><br>
  
      <input type="button" 
             value="Generate Table"
             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++)
            {
               // Update the properties of each cell. 
               Table1.Rows[i].Cells[j].Align = AlignSelect.Value; 
               Table1.Rows[i].Cells[j].NoWrap = Convert.ToBoolean(NoWrapSelect.Value);
               Table1.Rows[i].Cells[j].VAlign = VAlignSelect.Value; 
            }

         }

      }

   </script>

</head>
<body>

   <form runat="server">

      <h3>HtmlTableCell Example</h3>

      <table id="Table1" 
             Border="1" 
             BorderColor="black" 
             runat="server">

         <tr>
            <td>
               Here's some content for Cell 1.
            </td>
            <td>
               Here's some content for Cell 2.
            </td>
         </tr>
         <tr>
            <td Width="100" Height="100">
               Here's some content for Cell 3.
            </td>
            <td Width="100" Height="100">
               Here's 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="True">Left</option>
         <option Value="Center">Center</option>
         <option Value="Right">Right</option>
        
      </select>

      &nbsp;&nbsp;

      NoWrap:
      <select id="NoWrapSelect" 
              runat="server">

         <option Value="true">True</option>
         <option Value="false" Selected="True">False</option>

      </select>

      &nbsp;&nbsp;

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

         <option Value="Top">Top</option>
         <option Value="Middle" Selected="True">Middle</option>
         <option Value="Bottom">Bottom</option>

      </select>
       
      <br><br>
  
      <input type="button" 
             value="Generate Table"
             OnServerClick = "Button_Click" 
             runat="server"/>

   </form>

</body>
</html>

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

Requirements

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

See Also

HtmlTableCell Class | HtmlTableCell Members | System.Web.UI.HtmlControls Namespace | String.Empty | HtmlTable | ColSpan | NoWrap | RowSpan | VAlign

Show:
© 2016 Microsoft