This documentation is archived and is not being maintained.

HtmlTableCell.VAlign Property

Gets or sets the vertical alignment for the content of a cell represented by an instance of the HtmlTableCell class.

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

Property Value

The vertical alignment for the content of a 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 VAlign property to specify the vertical alignment of the content in a cell represented by an instance of the HtmlTableCell class.

Note   Setting this property only affects the cell represented by an instance of the HtmlTableCell class. To apply the same vertical alignment to the cells of an entire row in the table, set the VAlign 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
Top Aligns the contents of a cell with the upper edge of the cell.
Middle Aligns the contents of a cell in the center of the cell.
Bottom Aligns the contents of a cell with the lower edge of the cell.
Note   You can also use BaseLine as a value for this property. However, not all browsers support this feature.

Example

[Visual Basic, C#] The following example demonstrates how to use the VAlign property to programmatically control the vertical 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 | Align | ColSpan | NoWrap | RowSpan

Show: