Export (0) Print
Expand All

HtmlTableCell.VAlign Property

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

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

public string VAlign { get; set; }
<asp:HtmlTableCell VAlign="String" />

Property Value

Type: System.String
The vertical alignment for the content of a cell represented by an instance of HtmlTableCell. The default value is String.Empty, which indicates that this property is not set.

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

NoteNote

Setting this property affects only 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.

NoteNote

You can also use BaseLine as a value for this property. However, not all browsers support this feature.

The following code example demonstrates how to use the VAlign property to programmatically control the vertical alignment of the contents of the cells in an HtmlTable control.

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

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>HtmlTableCell Example</title>
</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>
               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;

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

         <option value="true">True</option>
         <option value="false" selected="selected">False</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

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft