Export (0) Print
Expand All

HtmlTableCellCollection.Remove Method

Removes the specified HtmlTableCell from the HtmlTableCellCollection.

[Visual Basic]
Public Sub Remove( _
   ByVal cell As HtmlTableCell _
)
[C#]
public void Remove(
 HtmlTableCell cell
);
[C++]
public: void Remove(
 HtmlTableCell* cell
);
[JScript]
public function Remove(
   cell : HtmlTableCell
);

Parameters

cell
The HtmlTableCell to remove from the HtmlTableCellCollection.

Remarks

Use this method to remove the specified HtmlTableCell from the HtmlTableCellCollection.

Note   If you specify an HtmlTableCell that does not exist in the HtmlTableCellCollection, no item is removed from the collection.

Example

[Visual Basic, C#, JScript] The following example demonstrates how to use the Remove method to remove the specified cell of a table, represented by a HtmlTableCell, from the HtmlTableCellCollection. This example removes the cells from the first column of the HtmlTable control.

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

<html>
<head>

   <script runat="server">

      Sub Button_Click(sender As Object, e As EventArgs) 

         Dim i As Integer
         Dim cell As HtmlTableCell

         ' Iterate through the rows of the table.
         For i=0 To Table1.Rows.Count - 1
 
            ' Remove the cells from the first column.
            cell = Table1.Rows(i).Cells(0)
            Table1.Rows(i).Cells.Remove(cell)

         Next i

      End Sub

   </script>

</head>
<body>

   <form runat="server">

      <h3>HtmlTableCellCollection Example</h3>

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

         <tr>
            <td>
               Cell 1
            </td>
            <td>
               Cell 2
            </td>
         </tr>
         <tr>
            <td>
               Cell 3
            </td>
            <td>
               Cell 4
            </td>
         </tr>

      </table>

      <br><br>
  
      <input type="button" 
             value="Remove First Column from Table"
             OnServerClick = "Button_Click" 
             runat="server"/>

   </form>

</body>
</html>

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

<html>
<head>

   <script runat="server">

      void Button_Click(Object sender, EventArgs e) 
      {

         // Iterate through the rows of the table.
         for (int i=0; i<=Table1.Rows.Count - 1; i++)
         {
 
            // Remove the cells from the first column.
            HtmlTableCell cell = Table1.Rows[i].Cells[0];
            Table1.Rows[i].Cells.Remove(cell);

         }

      }

   </script>

</head>
<body>

   <form runat="server">

      <h3>HtmlTableCellCollection Example</h3>

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

         <tr>
            <td>
               Cell 1
            </td>
            <td>
               Cell 2
            </td>
         </tr>
         <tr>
            <td>
               Cell 3
            </td>
            <td>
               Cell 4
            </td>
         </tr>

      </table>

      <br><br>
  
      <input type="button" 
             value="Remove First Column from Table"
             OnServerClick = "Button_Click" 
             runat="server"/>

   </form>

</body>
</html>

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

<html>
<head>

   <script runat="server">

      function Button_Click(sender : Object, e : EventArgs) 
      {

         // Iterate through the rows of the table.
         for (var i : int = 0; i <= Table1.Rows.Count - 1; i++)
         {
 
            // Remove the cells from the first column.
            var cell : HtmlTableCell = Table1.Rows[i].Cells[0];
            Table1.Rows[i].Cells.Remove(cell);

         }

      }

   </script>

</head>
<body>

   <form runat="server">

      <h3>HtmlTableCellCollection Example</h3>

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

         <tr>
            <td>
               Cell 1
            </td>
            <td>
               Cell 2
            </td>
         </tr>
         <tr>
            <td>
               Cell 3
            </td>
            <td>
               Cell 4
            </td>
         </tr>

      </table>

      <br><br>
  
      <input type="button" 
             value="Remove First Column from Table"
             OnServerClick = "Button_Click" 
             runat="server"/>

   </form>

</body>
</html>

[C++] No example is available for C++. To view a Visual Basic, C#, or JScript 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

HtmlTableCellCollection Class | HtmlTableCellCollection Members | System.Web.UI.HtmlControls Namespace | RemoveAt | Cells | HtmlTableRow

Show:
© 2014 Microsoft