This documentation is archived and is not being maintained.

HtmlTableCell.ColSpan Property

Gets or sets the number of columns occupied by a cell represented by an instance of the HtmlTableCell class.

[Visual Basic]
Public Property ColSpan As Integer
[C#]
public int ColSpan {get; set;}
[C++]
public: __property int get_ColSpan();
public: __property void set_ColSpan(int);
[JScript]
public function get ColSpan() : int;
public function set ColSpan(int);

Property Value

The number of columns occupied by the cell represented by an instance of the HtmlTableCell class. The default value is -1, which indicates that this property is not set.

Remarks

In a cell represented an instance of the HtmlTableCell class, use the ColSpan property to specify the number of columns the cell occupies. This allows you create a cell in the table that occupies more than one column. For example, suppose you have a table that contains two columns and two rows. You can create a table heading cell that spans both columns. Set the ColSpan property of the left-most cell in the first row to 2 to indicate that this cell takes up two columns in the table.

CAUTION   When spanning columns, be sure to define one less cell in the row for each column that you span. For example, if you span two columns, define one less cell in the current row. Otherwise, that row will be longer than the number of columns in the table and the table will not be displayed as expected.

Example

[Visual Basic, C#] The following example demonstrates how to use the ColSpan property to specify that the cell in the first row of the HtmlTable control takes up two columns.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
<head>

</head>
<body>

   <form runat="server">

      <h3>HtmlTableCell Example</h3>

      <table id="Table1" 
             Border="1" 
             BorderColor="black" 
             runat="server">

         <tr>
            <td ColSpan="2">
               Cell 1.
            </td>
         </tr>
         <tr>
            <td>
               Cell 3.
            </td>
            <td>
               Cell 4.
            </td>
         </tr>

      </table>      

   </form>

</body>
</html>

[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>

<html>
<head>

</head>
<body>

   <form runat="server">

      <h3>HtmlTableCell Example</h3>

      <table id="Table1" 
             Border="1" 
             BorderColor="black" 
             runat="server">

         <tr>
            <td ColSpan="2">
               Cell 1.
            </td>
         </tr>
         <tr>
            <td>
               Cell 3.
            </td>
            <td>
               Cell 4.
            </td>
         </tr>

      </table>      

   </form>

</body>
</html>

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

HtmlTableCell Class | HtmlTableCell Members | System.Web.UI.HtmlControls Namespace | Align | NoWrap | RowSpan | VAlign

Show: