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

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

DataKeyArray.GetEnumerator メソッド

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

コレクション内のすべての DataKey オブジェクト格納している列挙子を返します

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

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

returnValue = instance.GetEnumerator

戻り値
コレクション内のすべての DataKey オブジェクト格納している System.Collections.IEnumerator 実装オブジェクト

解説解説

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

メモメモ

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

使用例使用例

GetEnumerator メソッド作成され列挙子を反復処理する方法次のコード例示します

<%@ Page language="VB" %>

<script runat="server">

  Sub CustomerGridView_DataBound(ByVal sender
 As Object, ByVal e As
 EventArgs) Handles CustomerGridView.DataBound

    ' Use the Count property to determine whether the
    ' DataKeys collection contains any items.
    If CustomerGridView.DataKeys.Count > 0 Then

      MessageLabel.Text = "The primary key of each record displayed
 are: <br/><br/>"

      ' Use the GetEnumerator method to create an enumerator that 
      ' contains the DataKey objects for the GridView control.
      Dim keyEnumerator As IEnumerator = CustomerGridView.DataKeys.GetEnumerator()

      ' Iterate though the enumerator and display the primary key
      ' value of each record displayed.
      While keyEnumerator.MoveNext()
      
        Dim key As DataKey = CType(keyEnumerator.Current,
 DataKey)
        MessageLabel.Text &= key.Value.ToString() & "<br/>"
      
      End While

    Else
    
      MessageLabel.Text = "No DataKey objects."
    
    End If

  End Sub
  
</script>

<html>

  <body>
    <form runat="server">
        
      <h3>DataKeyArray Example</h3>
                       
        <asp:gridview id="CustomerGridView"
          datasourceid="CustomerDataSource"
          autogeneratecolumns="true"
          datakeynames="CustomerID"  
          allowpaging="true"
          runat="server">
            
        </asp:gridview>
        
        <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="CustomerDataSource"
          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 CustomerGridView_DataBound(Object sender, EventArgs e)
  {

    // Use the Count property to determine whether the
    // DataKeys collection contains any items.
    if (CustomerGridView.DataKeys.Count > 0)
    {

      MessageLabel.Text = "The primary key of each record displayed are: <br/><br/>";

      // Use the GetEnumerator method to create an enumerator that 
      // contains the DataKey objects for the GridView control.
      IEnumerator keyEnumerator = CustomerGridView.DataKeys.GetEnumerator();

      // Iterate though the enumerator and display the primary key
      // value of each record displayed.
      while (keyEnumerator.MoveNext())
      {
        DataKey key = (DataKey)keyEnumerator.Current;
        MessageLabel.Text += key.Value.ToString() + "<br/>";
      }

    }
    else
    {
      MessageLabel.Text = "No DataKey objects.";
    }

  }
  
</script>

<html>

  <body>
    <form runat="server">
        
      <h3>DataKeyArray Example</h3>
                       
        <asp:gridview id="CustomerGridView"
          datasourceid="CustomerDataSource"
          autogeneratecolumns="true"
          datakeynames="CustomerID"  
          allowpaging="true"
          ondatabound="CustomerGridView_DataBound" 
          runat="server">
            
        </asp:gridview>
        
        <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="CustomerDataSource"
          selectcommand="Select [CustomerID], [CompanyName], [Address], [City],
 [PostalCode], [Country] From [Customers]"
          connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
 
          runat="server"/>
            
      </form>
  </body>
</html>

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



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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS