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

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

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

GetEnumerator メソッドを使用して、項目を格納している列挙子をコレクションから取得する方法のコード例を次に示します。列挙子が反復処理され、各行の値がページに表示されます。
<%@ page language="VB" %> <script runat="server"> Sub SubmitButton_Click(ByVal sender As Object, ByVal e As EventArgs) ' Use the Count property to determine whether the ' Rows collection contains any item. If ItemDetailsView.Rows.Count > 0 Then MessageLabel.Text = "The row values are: <br/><br/>" ' Get the enumerator that contains the data rows in the ' DetailsView control. Dim rowEnumerator As IEnumerator = ItemDetailsView.Rows.GetEnumerator() ' Iterate though the enumerator and display the field values. While rowEnumerator.MoveNext() Dim row As DetailsViewRow = CType(rowEnumerator.Current, DetailsViewRow) ' Use the Text property to access the value of ' each cell. In this example, the cells in the ' first column (index 0) contains the field names, ' while the cells in the second column (index 1) ' contains the field value. MessageLabel.Text &= row.Cells(0).Text & " = " & _ row.Cells(1).Text & "<br/>" End While Else MessageLabel.Text = "No items." End If End Sub </script> <html> <body> <form runat="server"> <h3>DetailsViewRowCollection GetEnumerator Example</h3> <asp:detailsview id="ItemDetailsView" datasourceid="DetailsViewSource" allowpaging="true" autogeneraterows="false" runat="server"> <fields> <asp:boundfield datafield="CustomerID" headertext="Customer ID"/> <asp:boundfield datafield="CompanyName" headertext="Company Name"/> <asp:boundfield datafield="Address" headertext="Address"/> <asp:boundfield datafield="City" headertext="City"/> <asp:boundfield datafield="PostalCode" headertext="ZIP Code"/> <asp:boundfield datafield="Country" headertext="Country"/> </fields> </asp:detailsview> <br/> <asp:button id="SubmitButton" text="Display Row Values" onclick="SubmitButton_Click" runat="server"/> <br/><br/> <asp:label id="MessageLabel" forecolor="Red" runat="server"/> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the web.config file. --> <asp:sqldatasource id="DetailsViewSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" connectionstring= "<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body> </html>
<%@ page language="C#" %> <script runat="server"> void SubmitButton_Click(Object sender, EventArgs e) { // Use the Count property to determine whether the // Rows collection contains any item. if (ItemDetailsView.Rows.Count > 0) { MessageLabel.Text = "The row values are: <br/><br/>"; // Get the enumerator that contains the data rows in the // DetailsView control. IEnumerator rowEnumerator = ItemDetailsView.Rows.GetEnumerator(); // Iterate though the enumerator and display the field values. while (rowEnumerator.MoveNext()) { DetailsViewRow row = (DetailsViewRow)rowEnumerator.Current; // Use the Text property to access the value of // each cell. In this example, the cells in the // first column (index 0) contains the field names, // while the cells in the second column (index 1) // contains the field value. MessageLabel.Text += row.Cells[0].Text + " = " + row.Cells[1].Text + "<br/>"; } } else { MessageLabel.Text = "No items."; } } </script> <html> <body> <form runat="server"> <h3>DetailsViewRowCollection GetEnumerator Example</h3> <asp:detailsview id="ItemDetailsView" datasourceid="DetailsViewSource" allowpaging="true" autogeneraterows="false" runat="server"> <fields> <asp:boundfield datafield="CustomerID" headertext="Customer ID"/> <asp:boundfield datafield="CompanyName" headertext="Company Name"/> <asp:boundfield datafield="Address" headertext="Address"/> <asp:boundfield datafield="City" headertext="City"/> <asp:boundfield datafield="PostalCode" headertext="ZIP Code"/> <asp:boundfield datafield="Country" headertext="Country"/> </fields> </asp:detailsview> <br/> <asp:button id="SubmitButton" text="Display Row Values" onclick="SubmitButton_Click" runat="server"/> <br/><br/> <asp:label id="MessageLabel" forecolor="Red" runat="server"/> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the web.config file. --> <asp:sqldatasource id="DetailsViewSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" connectionstring= "<%$ ConnectionStrings:NorthWindConnectionString%>" 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からDetailsViewRowCollection.GetEnumerator メソッドを検索する場合は、下記のリンクをクリックしてください。

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