GridViewRowCollection.GetEnumerator メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > GridViewRowCollection.GetEnumerator メソッドの意味・解説 

GridViewRowCollection.GetEnumerator メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

GridViewRowCollection 内のすべての GridViewRow オブジェクト格納している列挙子を返します

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Function GetEnumerator As
 IEnumerator
Dim instance As GridViewRowCollection
Dim returnValue As IEnumerator

returnValue = instance.GetEnumerator

戻り値
GridViewRowCollectionすべての GridViewRow オブジェクト格納している System.Collections.IEnumerator 実装オブジェクト

解説解説

このメソッド使用してGridViewRowCollection 内の各項目に直接アクセスするために反復処理できる列挙子を取得します列挙子の現在の位置の項目にアクセスするには、IEnumerator.Current プロパティ使用します。IEnumerator.MoveNext メソッド使用してコレクション内の次の項目に移動します列挙子を最初位置まで移動するには、IEnumerator.Reset メソッド使用します

メモメモ

最初に列挙子を取得した場合、または IEnumerator.Reset メソッド使用して列挙子をコレクション最初の項目に移動した場合は、IEnumerator.MoveNext メソッド呼び出す必要があります。このメソッド呼び出さないと、IEnumerator.Current プロパティ表される項目は未定義になります

使用例使用例

GetEnumerator メソッド使用してコレクションの値を格納している列挙子を取得する方法次の例に示します。この列挙子が反復処理され、最初セルの値がページ表示されます。

<%@ Page language="VB" %>

<script runat="server">

  Sub AuthorsGridView_RowCreated(ByVal sender
 As Object, ByVal e As
 GridViewRowEventArgs)

    If e.Row.RowType = DataControlRowType.Footer Then
    
      Message.Text = "The authors are:<br>"
      
      ' Get the enumerator that contains the data rows in the 
      ' GridView control.
      Dim rowEnumerator As IEnumerator = AuthorsGridView.Rows.GetEnumerator()

      ' Iterate though the enumerator and display the value in the
      ' first cell of the row.
      While rowEnumerator.MoveNext()

        Dim row As GridViewRow = CType(rowEnumerator.Current,
 GridViewRow)
        Message.Text &= row.Cells(0).Text & "<br>"
      
      End While
      
    End If
  
  End Sub

</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridViewRowCollection GetEnumerator Example</h3>

      <table>
        <tr>
          <td>
            <asp:gridview id="AuthorsGridView"
 
              datasourceid="AuthorsSqlDataSource"
 
              autogeneratecolumns="false"
              onrowcreated="AuthorsGridView_RowCreated"
  
              runat="server"> 
                     
              <columns>
                <asp:boundfield datafield="au_lname"
                  headertext="Last Name"/>
                <asp:boundfield datafield="au_fname"
                  headertext="First Name"/>
              </columns>
                                    
            </asp:gridview>
          </td>
          <td>
            <asp:label id="Message" 
              forecolor="Red"
              runat="server"/>
          </td>
        </tr>
      </table>
            
      <!-- This example uses Microsoft SQL Server and connects
 -->
      <!-- to the Pubs sample database.                   
     -->
      <asp:sqldatasource id="AuthorsSqlDataSource"
  
        selectcommand="SELECT [au_lname], [au_fname] FROM [authors] WHERE [state]='CA'"
        connectionstring="server=localhost;database=pubs;integrated
 security=SSPI"
        runat="server">
      </asp:sqldatasource>
          
    </form>
  </body>
</html>

<%@ Page language="C#" %>

<script runat="server">

  void AuthorsGridView_RowCreated(Object sender, GridViewRowEventArgs
 e)
  {
    if (e.Row.RowType == DataControlRowType.Footer)
    {
      Message.Text = "The authors are:<br>";
      
      // Get the enumerator that contains the data rows in the 
      // GridView control.
      IEnumerator rowEnumerator = AuthorsGridView.Rows.GetEnumerator();

      // Iterate though the enumerator and display the value in the
      // first cell of the row.
      while(rowEnumerator.MoveNext())
      {
        GridViewRow row = (GridViewRow)rowEnumerator.Current;
        Message.Text += row.Cells[0].Text + "<br>";
      }
    }
  }

</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridViewRowCollection GetEnumerator Example</h3>

      <table>
        <tr>
          <td>
            <asp:gridview id="AuthorsGridView" 
              datasourceid="AuthorsSqlDataSource" 
              autogeneratecolumns="false"
              onrowcreated="AuthorsGridView_RowCreated"  
              runat="server"> 
                     
              <columns>
                <asp:boundfield datafield="au_lname"
                  headertext="Last Name"/>
                <asp:boundfield datafield="au_fname"
                  headertext="First Name"/>
              </columns>
                                    
            </asp:gridview>
          </td>
          <td>
            <asp:label id="Message" 
              forecolor="Red"
              runat="server"/>
          </td>
        </tr>
      </table>
            
      <!-- This example uses Microsoft SQL Server and connects -->
      <!-- to the Pubs sample database.                        -->
      <asp:sqldatasource id="AuthorsSqlDataSource"  
        selectcommand="SELECT [au_lname], [au_fname] FROM [authors] WHERE [state]='CA'"
        connectionstring="server=localhost;database=pubs;integrated security=SSPI"
        runat="server">
      </asp:sqldatasource>
          
    </form>
  </body>
</html>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
GridViewRowCollection クラス
GridViewRowCollection メンバ
System.Web.UI.WebControls 名前空間
System.Collections.IEnumerator
IEnumerator.Current
IEnumerator.MoveNext
IEnumerator.Reset
Item
CopyTo



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

GridViewRowCollection.GetEnumerator メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



GridViewRowCollection.GetEnumerator メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS