Upraviť

Zdieľať cez


HtmlTableCell.ColSpan Property

Definition

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

public:
 property int ColSpan { int get(); void set(int value); };
public int ColSpan { get; set; }
member this.ColSpan : int with get, set
Public Property ColSpan As Integer

Property Value

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

Examples

The following code 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.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>HtmlTableCell Example</title>
</head>
<body>

   <form id="form1" runat="server">

      <h3>HtmlTableCell Example</h3>

          <table id="Table1" runat="server" 
                style="border-width: 1; border-color: Black">

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

      </table>      

   </form>

</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>HtmlTableCell Example</title>
</head>
<body>

   <form id="form1" runat="server">

      <h3>HtmlTableCell Example</h3>

          <table id="Table1" runat="server" 
                style="border-width: 1; border-color: Black">

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

      </table>      

   </form>

</body>
</html>

Remarks

In a cell represented by an instance of the HtmlTableCell class, use the ColSpan property to specify the number of columns the cell occupies. This allows you to 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 leftmost 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 fewer cell in the row for each column that you span. For example, if you span two columns, define one fewer 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.

Applies to

See also