HtmlTableRowCollection.GetEnumerator メソッド
アセンブリ: System.Web (system.web.dll 内)

Dim instance As HtmlTableRowCollection Dim returnValue As IEnumerator returnValue = instance.GetEnumerator
public IEnumerator GetEnumerator ()
public: virtual IEnumerator^ GetEnumerator () sealed
public final IEnumerator GetEnumerator ()
public final function GetEnumerator () : IEnumerator
HtmlTableRowCollection のすべての HtmlTableRow オブジェクトを格納する System.Collections.IEnumerator 実装オブジェクト。

このメソッドを使用して、HtmlTableRowCollection コレクションの各項目を取得する場合に反復処理できる System.Collections.IEnumerator 実装オブジェクトを作成します。
IEnumerator.Current プロパティを使用して、コレクション内の現在の要素を取得します。
IEnumerator.MoveNext メソッドを使用して、コレクション内の次の項目に移動します。
IEnumerator.Reset メソッドを使用して、列挙子を最初の位置に移動します。
![]() |
---|
System.Collections.IEnumerator 実装オブジェクトの作成後または IEnumerator.Reset メソッドの使用後に IEnumerator.MoveNext メソッドを呼び出して、列挙子をコレクションの最初の項目に移動する必要があります。このメソッドを呼び出さないと、IEnumerator.Current プロパティで表される項目は未定義になります。 |

GetEnumerator メソッドを使用して、System.Collections.IEnumerator オブジェクトを作成する方法を次のコード例に示します。その後、System.Collections.IEnumerator オブジェクトは反復処理され、HtmlTableRowCollection コレクションの内容が表示されます。
<%@ Page Language="VB" AutoEventWireup="True" %> <script runat="server"> Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs) Dim current_row As HtmlTableRow ' Create an IEnumerator enumerator. 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> <html> <head> <title>HtmlTableRowCollection Example</title> </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 row contents in the table" onserverclick="Button_Click" runat="server"/> <br><br> <span id="Span1" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="True" %> <script runat="server"> void Button_Click(Object sender, EventArgs e) { HtmlTableRow current_row; // Create an IEnumerator enumerator. 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> <html> <head> <title>HtmlTableRowCollection Example</title> </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 row contents in the table" onserverclick="Button_Click" runat="server"/> <br><br> <span id="Span1" runat="server"/> </form> </body> </html>
<%@ Page Language="JScript" AutoEventWireup="True" %> <script runat="server"> function Button_Click(sender, e : EventArgs) { var current_row : HtmlTableRow; // Create an IEnumerator enumerator. 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> <html> <head> <title>HtmlTableRowCollection Example</title> </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 row contents in the table" onserverclick="Button_Click" runat="server"/> <br><br> <span id="Span1" runat="server"/> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- HtmlTableRowCollection.GetEnumerator メソッドのページへのリンク