HtmlTableCellCollection.GetEnumerator Method
Returns a System.Collections.IEnumerator implemented object that contains all HtmlTableCell objects in the HtmlTableCellCollection.
[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 HtmlTableCell objects in the HtmlTableCellCollection.
Implements
Remarks
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.
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 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.
Example
[Visual Basic, C#, JScript] The following 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.
[Visual Basic] <%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script runat="server"> Sub Button_Click(sender As Object, e As EventArgs) Dim current_cell As HtmlTableCell ' Create IEnumerator. Dim myEnum As IEnumerator = 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 = CType(myEnum.Current,HtmlTableCell) Span1.InnerText = Span1.InnerText & " " & current_cell.InnerText End While 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="Display the contents of the first row." 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) { HtmlTableCell current_cell; // Create IEnumerator. 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> </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="Display the contents of the first row." 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_cell : HtmlTableCell; // Create IEnumerator. var myEnum : IEnumerator = 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> </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="Display the contents of the first row." 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
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 | System.Collections.IEnumerator | HtmlTableCell | IEnumerator.Current | IEnumerator.MoveNext | IEnumerator.Reset