GridViewRowCollection.Count プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > GridViewRowCollection.Count プロパティの意味・解説 

GridViewRowCollection.Count プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

GridViewRowCollection オブジェクト内の項目の数を取得します

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

解説解説
使用例使用例

Count プロパティ使用して、GridView コントロールレコード含まれているかどうか確認する方法次の例に示します。値が 0 より大きい場合は、GridView コントロール1 つ上のレコード含まれていることを示します

<%@ Page language="VB" %>

<script runat="server">

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

    If e.Row.RowType = DataControlRowType.Footer Then
      
      ' Get the number of items in the Rows collection.
      Dim count As Integer
 = AuthorsGridView.Rows.Count

      ' If the GridView control contains any records, display 
      ' the last name of each author in the GridView control.
      If count > 0 Then
           
        Message.Text = "The authors are:<br>"
        
        Dim row As GridViewRow
        For Each row In
 AuthorsGridView.Rows
        
          Message.Text &= row.Cells(0).Text & "<br>"
        
        Next
        
      End If
        
    End If
        
  End Sub

</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridViewRowCollection 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)
    {      
      
      // Get the number of items in the Rows collection.
      int count = AuthorsGridView.Rows.Count;

      // If the GridView control contains any records, display 
      // the last name of each author in the GridView control.
      if (count > 0)
      {      
        Message.Text = "The authors are:<br>";
        
        foreach (GridViewRow row in AuthorsGridView.Rows)
        {
          Message.Text += row.Cells[0].Text + "<br>";
        }
      }
      
    }
  }

</script>

<html>
  <body>
    <form runat="server">
        
      <h3>GridViewRowCollection 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 名前空間
Item


このページでは「.NET Framework クラス ライブラリ リファレンス」からGridViewRowCollection.Count プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からGridViewRowCollection.Count プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からGridViewRowCollection.Count プロパティ を検索

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

辞書ショートカット

すべての辞書の索引

GridViewRowCollection.Count プロパティのお隣キーワード
検索ランキング

   

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



GridViewRowCollection.Count プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS