This documentation is archived and is not being maintained.

HtmlTableRowCollection.GetEnumerator Method

Returns a System.Collections.IEnumerator implemented object that contains all HtmlTableRow objects in the HtmlTableRowCollection.

[Visual Basic]
Public Overridable Function GetEnumerator() As IEnumerator _
   Implements IEnumerable.GetEnumerator
[C#]
public virtual IEnumerator GetEnumerator();
[C++]
public: virtual IEnumerator* GetEnumerator();
[JScript]
public function GetEnumerator() : IEnumerator;

Return Value

A System.Collections.IEnumerator implemented object that contains all HtmlTableRow objects in the HtmlTableRowCollection.

Implements

IEnumerable.GetEnumerator

Remarks

Use this method to create a System.Collections.IEnumerator implemented object that can be iterated through to get each item in the HtmlTableRowCollection.

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.

Note   The IEnumerator.MoveNext method must be called after creating a 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.

Example

[Visual Basic, C#, JScript] The following example demonstrates how to use the GetEnumerator method to create a System.Collections.IEnumerator object. The System.Collections.IEnumerator object is then iterated through to display the contents of the HtmlTableRowCollection.

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

<html>
<head>

   <script runat="server">

      Sub Button_Click(sender As Object, e As EventArgs) 
 
         Dim current_row As HtmlTableRow

         ' Create IEnumerator.
         Dim myEnum As IEnumerator = Table1.Rows.GetEnumerator()      

         Span1.InnerText = "The items in the rows of the table are: "

         ' Iterate through the IEnumerator and display its contents.
         While myEnum.MoveNext() 
         
            current_row = CType(myEnum.Current, HtmlTableRow)
            Span1.InnerText = Span1.InnerText & " " & current_row.Cells(0).InnerText & _
                              " " & current_row.Cells(1).InnerText

         End While

      End Sub

   </script>

</head>
<body>

   <form runat="server">

      <h3>HtmlTableRowCollection 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="Display the contents of the rows in the table"
             OnServerClick = "Button_Click" 
             runat="server"/>

      <br><br>

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

   </form>

</body>
</html>

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

<html>
<head>

   <script runat="server">

      void Button_Click(Object sender, EventArgs e) 
      {
 
         HtmlTableRow current_row;

         // Create IEnumerator.
         IEnumerator myEnum = Table1.Rows.GetEnumerator();      

         Span1.InnerText = "The items in the rows of the table are: ";

         // Iterate through the IEnumerator and display its contents.
         while (myEnum.MoveNext()) 
         {
         
            current_row = (HtmlTableRow)myEnum.Current;
            Span1.InnerText = Span1.InnerText + " " + current_row.Cells[0].InnerText +
                              " " + current_row.Cells[1].InnerText;

         }

      }

   </script>

</head>
<body>

   <form runat="server">

      <h3>HtmlTableRowCollection 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="Display the contents of the rows in the table"
             OnServerClick = "Button_Click" 
             runat="server"/>

      <br><br>

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

   </form>

</body>
</html>

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

<html>
<head>

   <script runat="server">

      function Button_Click(sender, e : EventArgs) 
      {
 
         var current_row : HtmlTableRow;

         // Create IEnumerator.
         var myEnum : IEnumerator = Table1.Rows.GetEnumerator();      

         Span1.InnerText = "The items in the rows of the table are: ";

         // Iterate through the IEnumerator and display its contents.
         while (myEnum.MoveNext()) 
         {
         
            current_row = HtmlTableRow(myEnum.Current);
            Span1.InnerText = Span1.InnerText + " " + current_row.Cells[0].InnerText +
                              " " + current_row.Cells[1].InnerText;

         }

      }

   </script>

</head>
<body>

   <form runat="server">

      <h3>HtmlTableRowCollection 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="Display the contents of the rows in the table"
             OnServerClick = "Button_Click" 
             runat="server"/>

      <br><br>

      <span id="Span1"
            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

HtmlTableRowCollection Class | HtmlTableRowCollection Members | System.Web.UI.HtmlControls Namespace | System.Collections.IEnumerator | HtmlTableRow | IEnumerator.Current | IEnumerator.MoveNext | IEnumerator.Reset

Show: