Export (0) Print
Expand All

HtmlTableCellCollection.Clear Method

Removes all HtmlTableCell objects from the HtmlTableCellCollection.

[Visual Basic]
Public Sub Clear()
[C#]
public void Clear();
[C++]
public: void Clear();
[JScript]
public function Clear();

Remarks

Use this method to remove all HtmlTableCell objects from the HtmlTableCellCollection and reset the Count property to 0.

Note   This method removes the cells from a row, but it does not remove the row from the table. To remove a row from the table, be sure to also remove the HtmlTableRow that represents the row from the Rows collection of the HtmlTable control.

Example

[Visual Basic, C#, JScript] The following example demonstrates how to use the Clear method to remove all items from the HtmlTableCellCollection. New entries are then added to the collection and displayed in the HtmlTable control.

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

<html>
<head>

   <script runat="server">

      Sub Button_Click(sender As Object, e As EventArgs) 
 
         ' Clear the cells from the first row and remove the 
         ' row from the table.
         Table1.Rows(0).Cells.Clear()
         Table1.Rows.RemoveAt(0)

      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 Row 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) 
      {
 
         // Clear the cells from the first row and remove the 
         // row from the table.
         Table1.Rows[0].Cells.Clear();
         Table1.Rows.RemoveAt(0);

      }

   </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 Row 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) 
      {
 
         // Clear the cells from the first row and remove the 
         // row from the table.
         Table1.Rows[0].Cells.Clear();
         Table1.Rows.RemoveAt(0);

      }

   </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 Row 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 | HtmlTableCell | HtmlTableRow | Cells | Count

Show:
© 2015 Microsoft