asp.net.ph

HtmlTableCell.ColSpan Property

System.Web.UI.HtmlControls Namespace   HtmlTableCell Class


Sets or retrieves the number of columns that the HtmlTableCell control spans.

Syntax


Inline <th | td colspan = intCols ... >
Script [ HtmlTableHeaderCell | HtmlTableCell ].ColSpan [ = intCols ]

Property Value


intCols Integer specifying the number of columns the HtmlTableCell occupies.

The property is read/write with a default value of -1 ( not enabled ).

Remarks

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.

Example

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 1Cell 2Cell 3
Cell 4Cell 5Cell 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.

See Also

HtmlTableCell Members   RowSpan Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph