YouTip LogoYouTip

Prop Webcontrol Tablecell Verticallalign

## ASP.NET TableCell VerticalAlign Property The `VerticalAlign` property is a member of the `TableCell` Web Control in ASP.NET. It is used to get or set the vertical alignment of the content within an individual table cell. --- ## Definition and Usage The `VerticalAlign` property determines how text, images, or other controls inside a `TableCell` are aligned vertically (top, middle, bottom) relative to the cell's boundaries. This is highly useful for controlling the layout and readability of tabular data. --- ## Syntax ```xml ``` ### Property Values | Value | Description | | :--- | :--- | | **NotSet** | The vertical alignment is not set. The browser will use its default alignment behavior (typically middle or top depending on the browser and CSS). | | **Top** | Aligns the content with the top border of the cell. | | **Middle** | Centers the content vertically within the cell. | | **Bottom** | Aligns the content with the bottom border of the cell. | --- ## Code Examples ### Example 1: Declarative Markup (ASPX) The following example demonstrates how to set the `VerticalAlign` property directly in the `.aspx` markup. In this example, the first cell's content is vertically centered, while the second cell uses the default alignment. ```xml
Centered Content Default Content
``` ### Example 2: Programmatic Approach (C# Behind-the-Code) You can also set or change the `VerticalAlign` property dynamically in your code-behind file using the `VerticalAlign` enumeration. ```csharp using System; using System.Web.UI.WebControls; protected void Page_Load(object sender, EventArgs e) { // Create a new TableCell TableCell cell = new TableCell(); cell.Text = "Top Aligned Content"; // Set the vertical alignment programmatically cell.VerticalAlign = VerticalAlign.Top; // Add the cell to an existing TableRow (assuming row1 is defined in markup) row1.Cells.Add(cell); } ``` --- ## Considerations and Best Practices 1. **Inheritance**: If you do not explicitly set the `VerticalAlign` property on a `TableCell`, it may inherit its alignment behavior from the parent `TableRow` or `Table` control if those controls have their vertical alignment properties defined. 2. **CSS Alternatives**: While the `VerticalAlign` property is convenient, modern web development often favors using CSS classes (`vertical-align: top;` etc.) via the `CssClass` property to keep presentation styles separated from server-side markup. 3. **Height Dependency**: Vertical alignment is only visually noticeable if the height of the `TableCell` or its parent `TableRow` is greater than the height of the content inside the cell.
← Prop Webcontrol Tablecell WrapProp Webcontrol Tablecell Text β†’