System.Web.UI.HtmlControls Namespace HtmlTableCell Class
Sets or retrieves the number of columns that the HtmlTableCell control spans.
Inline |
<th | td colspan = intCols ... > |
Script |
[ HtmlTableHeaderCell | HtmlTableCell ].ColSpan [ = intCols ] |
intCols |
Integer specifying the number of columns the HtmlTableCell occupies. |
The property is read/write with a default value of -1 ( not enabled ).
Cells can be merged, or can span columns or rows.
Use the ColSpan property to specify how many columns in the HtmlTable the cell should span. This allows you to create a cell in the table that occupies more than one column.
When spanning columns, be sure to define one less cell in the row for each column that you span, as shown in the sample below. Otherwise, that row will have more than the number of columns in the table and the table will not be rendered as expected.
NOTE: Specifying a zero value for ColSpan means that the cell spans all columns from the current column to the last column of the column group in which the cell is defined.
The following shows how to declaratively set the ColSpan property of an HtmlTableCell at design time.
<table width="70%" align="center" border=1 cellpadding=10 runat="server">
<tr>
<th colspan=3>This header spans 3 columns</th></tr>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td></tr>
<tr>
<td>Cell 4</td>
<td>Cell 5</td>
<td>Cell 6</td></tr>
</table>
Which would render as follows:
This header spans 3 columns |
Cell 1 | Cell 2 | Cell 3 |
Cell 4 | Cell 5 | Cell 6 |
Notice that instead of having three <th> elements for the first row, here we only have one <th> with its ColSpan attribute set to 3. This tells the browser that this <th> occupies, or spans, three columns contained in the row.
HtmlTableCell Members RowSpan