YouTip LogoYouTip

Prop Webcontrol Tablecell Rowspan

## ASP.NET TableCell RowSpan Property The `RowSpan` property is a member of the `TableCell` Web Control in ASP.NET. It is used to get or set the number of rows in a `Table` control that an individual table cell should span. --- ## Definition and Usage The `RowSpan` property allows a single table cell (``) to extend vertically across multiple rows. This is highly useful for creating complex grid layouts, grouping related data, or designing custom report templates where a single category label applies to multiple rows of data. When rendered, this property translates directly to the standard HTML `rowspan` attribute of the `` element. --- ## Syntax ### Declarative Syntax ```xml ``` ### Property Values | Attribute Value | Description | | :--- | :--- | | **num** | An integer that specifies the number of rows the table cell should span. The default value is `0` (which indicates that the property is not set). | --- ## Code Examples ### Example 1: Basic Declarative Implementation The following example demonstrates how to set the `RowSpan` property to `"2"` in your markup. This makes the first cell of the first row span across both the first and second rows. ```xml
<%-- Row 1 --%> This cell spans 2 rows. Row 1, Cell 2 <%-- Row 2 --%> Row 2, Cell 2 (Row 2, Cell 1 is occupied by the spanned cell above)
``` ### Example 2: Programmatic Implementation (C#) You can also set or modify the `RowSpan` property dynamically in your code-behind file. ```csharp protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // Create a new TableCell TableCell cell = new TableCell(); cell.Text = "Dynamically Spanned Cell"; // Set the RowSpan property programmatically cell.RowSpan = 3; // Add the cell to a TableRow (assuming row1 is defined in your .aspx markup) row1.Cells.Add(cell); } } ``` --- ## Considerations and Best Practices 1. **Layout Alignment**: When you set `RowSpan="n"` on a cell, the subsequent `n-1` rows must define one fewer `` element in their markup. If you do not adjust the cell count in the subsequent rows, the table layout will shift to the right and become misaligned. 2. **Default Value**: The default value of this property is `0`. When set to `0`, it behaves as if the attribute is not defined, meaning the cell spans only its native single row. 3. **Browser Compatibility**: The `RowSpan` property renders as the standard HTML `rowspan` attribute, which is fully supported by all modern web browsers.
← Prop Webcontrol Tablecell TextProp Webcontrol Tablecell Hori β†’