Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

HtmlTableCellCollection.GetEnumerator Method

Returns a System.Collections.IEnumerator-implemented object that contains all HtmlTableCell objects in the HtmlTableCellCollection collection.

Namespace:  System.Web.UI.HtmlControls
Assembly:  System.Web (in System.Web.dll)

public IEnumerator GetEnumerator()

Return Value

Type: System.Collections.IEnumerator
A System.Collections.IEnumerator-implemented object that contains all HtmlTableCell objects in the HtmlTableCellCollection.

Implements

IEnumerable.GetEnumerator()

Use this method to create a System.Collections.IEnumerator-implemented object that can be iterated through to retrieve the contents of each item in the HtmlTableCellCollection collection.

Use the IEnumerator.Current property to get the item currently pointed to in the collection.

Use the IEnumerator.MoveNext method to move to the next item in the collection.

Use the IEnumerator.Reset method to move the enumerator to the initial position.

NoteNote

The IEnumerator.MoveNext method must be called after creating the System.Collections.IEnumerator-implemented object, or after using the IEnumerator.Reset method to move the enumerator to the first item in the collection. Otherwise, the item represented by the IEnumerator.Current property is undefined.

The following code example demonstrates how to use the GetEnumerator method to create a System.Collections.IEnumerator-implemented object. The object is then iterated through to display the contents of the HtmlTableCellCollection collection.

<%@ 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">
<script runat="server">

  void Button_Click(Object sender, EventArgs e)
  {

    HtmlTableCell current_cell;

    // Create an IEnumerator instance.
    IEnumerator myEnum = Table1.Rows[0].Cells.GetEnumerator();

    Span1.InnerText = "The items in the first row are: ";

    // Iterate through the IEnumerator and display its contents.
    while (myEnum.MoveNext())
    {

      current_cell = (HtmlTableCell)myEnum.Current;
      Span1.InnerText = Span1.InnerText + " " + current_cell.InnerText;

    }

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>HtmlTableCellCollection Example</title>
</head>
<body>

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

      <h3>HtmlTableCellCollection Example</h3>

      <table id="Table1" 
             style="border-width:1; border-color: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="Display the contents of the first row"
             onserverclick="Button_Click" 
             runat="server"/>

      <br /><br />

      <span id="Span1"
            runat="server"/>

   </form>

</body>
</html>

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
Show:
© 2015 Microsoft