Suggérer une traduction
 
Suggestions d'autres utilisateurs :

progress indicator
Aucune autre suggestion.
Cliquez pour évaluer et commenter
MSDN
MSDN Library
Développement .NET
.NET Framework 4
Espaces de noms System.Web
System.Web.UI.WebControls
GridViewRowCollection, classe
Réduire tout/Développer tout Réduire tout
Affichage du contenu :  côte à côteAffichage du contenu : côte à côte
.NET Framework Class Library
GridViewRowCollection Class

Represents a collection of GridViewRow objects in a GridView control.

System..::.Object
  System.Web.UI.WebControls..::.GridViewRowCollection

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
Visual Basic
Public Class GridViewRowCollection _
    Implements ICollection, IEnumerable
C#
public class GridViewRowCollection : ICollection, 
    IEnumerable
Visual C++
public ref class GridViewRowCollection : ICollection, 
    IEnumerable
F#
type GridViewRowCollection =  
    class
        interface ICollection
        interface IEnumerable
    end

The GridViewRowCollection type exposes the following members.

  NameDescription
Public methodGridViewRowCollectionInitializes a new instance of the GridViewRowCollection class using the specified System.Collections..::.ArrayList object.
Top
  NameDescription
Public propertyCountGets the number of items in the GridViewRowCollection object.
Public propertyIsReadOnlyGets a value indicating whether the rows in the GridViewRowCollection object can be modified.
Public propertyIsSynchronizedGets a value indicating whether the GridViewRowCollection object is synchronized (thread-safe).
Public propertyItemGets the GridViewRow object at the specified index.
Public propertySyncRootGets the object used to synchronize access to the collection.
Top
  NameDescription
Public methodCopyToCopies all the items from this GridViewRowCollection to the specified System..::.Array object, starting at the specified index in the System..::.Array object.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetEnumeratorReturns an enumerator that contains all GridViewRow objects in the GridViewRowCollection.
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top
  NameDescription
Public Extension MethodAsParallelEnables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension MethodAsQueryableConverts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodCast<(Of <(TResult>)>)Converts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodOfType<(Of <(TResult>)>)Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Top
  NameDescription
Explicit interface implemetationPrivate methodICollection..::.CopyToInfrastructure. For a description of this member, see CopyTo.
Top

The GridViewRowCollection class is used to store and manage a collection of GridViewRow objects in a GridView control. Each row in a GridView control is represented by a GridViewRow object. The GridView control stores all of its data rows in the Rows collection.

The GridViewRowCollection class supports several ways to access the items in the collection:

  • Use the Item indexer to directly retrieve a GridViewRow object at a specific zero-based index.

  • Use the GetEnumerator method to retrieve an enumerator that can be used to iterate through the collection.

  • Use the CopyTo method to copy the items in the collection into an System..::.Array object, which can then be used to access the items in the collection.

To determine the total number of items in the collection, use the Count property

The following example demonstrates how to iterate through the Rows collection of a GridView control and display the values of a column on the page.

Visual Basic

<%@ Page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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  >
  <head runat="server">
    <title>GridViewRowCollection Example</title>
</head>
<body>
    <form id="form1" 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>

C#

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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  >
  <head runat="server">
    <title>GridViewRowCollection Example</title>
</head>
<body>
    <form id="form1" 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>

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Bibliothèque de classes .NET Framework
GridViewRowCollection, classe

Représente une collection d'objets GridViewRow dans un contrôle GridView.

System..::.Object
  System.Web.UI.WebControls..::.GridViewRowCollection

Espace de noms :  System.Web.UI.WebControls
Assembly :  System.Web (dans System.Web.dll)
Visual Basic
Public Class GridViewRowCollection _
    Implements ICollection, IEnumerable
C#
public class GridViewRowCollection : ICollection, 
    IEnumerable
VisualC++
public ref class GridViewRowCollection : ICollection, 
    IEnumerable
F#
type GridViewRowCollection =  
    class
        interface ICollection
        interface IEnumerable
    end

Le type GridViewRowCollection expose les membres suivants.

  NomDescription
Méthode publiqueGridViewRowCollectionInitialise une nouvelle instance de la classe GridViewRowCollection à l'aide de l'objet System.Collections..::.ArrayList spécifié.
Début
  NomDescription
Propriété publiqueCountObtient le nombre d'éléments dans l'objet GridViewRowCollection.
Propriété publiqueIsReadOnlyObtient une valeur indiquant si les lignes de l'objet GridViewRowCollection peuvent être modifiées.
Propriété publiqueIsSynchronizedObtient une valeur indiquant si l'objet GridViewRowCollection est synchronisé (thread-safe).
Propriété publiqueItemObtient l'objet GridViewRow à l'index spécifié.
Propriété publiqueSyncRootObtient l'objet utilisé pour synchroniser l'accès à la collection.
Début
  NomDescription
Méthode publiqueCopyToCopie tous les éléments de ce GridViewRowCollection dans l'objet System..::.Array spécifié, en commençant à l'index spécifié dans l'objet System..::.Array.
Méthode publiqueEquals(Object)Détermine si l'Object spécifié est égal à l'Object en cours. (Hérité de Object.)
Méthode protégéeFinalizeAutorise un objet à tenter de libérer des ressources et d'exécuter d'autres opérations de netto***ge avant qu'il ne soit récupéré par l'opération garbage collection. (Hérité de Object.)
Méthode publiqueGetEnumeratorRetourne un énumérateur qui contient tous les objets GridViewRow de GridViewRowCollection.
Méthode publiqueGetHashCodeSert de fonction de hachage pour un type particulier. (Hérité de Object.)
Méthode publiqueGetTypeObtient le Type de l'instance actuelle. (Hérité de Object.)
Méthode protégéeMemberwiseCloneCrée une copie superficielle de l'objet Object actif. (Hérité de Object.)
Méthode publiqueToStringRetourne une chaîne qui représente l'objet actuel. (Hérité de Object.)
Début
  NomDescription
Méthode d'extension publiqueAsParallelActive la parallélisation d'une requête. (Défini par ParallelEnumerable.)
Méthode d'extension publiqueAsQueryableConvertit un IEnumerable en IQueryable. (Défini par Queryable.)
Méthode d'extension publiqueCast<(Of <(TResult>)>)Convertit les éléments d'un IEnumerable vers le type spécifié. (Défini par Enumerable.)
Méthode d'extension publiqueOfType<(Of <(TResult>)>)Filtre les éléments d'un IEnumerable en fonction du type spécifié. (Défini par Enumerable.)
Début
  NomDescription
Implémentation d'interface expliciteMéthode privéeICollection..::.CopyToInfrastructure. Pour une description de ce membre, consultez CopyTo.
Début

La classe GridViewRowCollection est utilisée pour stocker et gérer une collection d'objets GridViewRow dans un contrôle GridView. Chaque ligne d'un contrôle GridView est représentée par un objet GridViewRow. Le contrôle GridView stocke toutes ses lignes de données dans la collection Rows.

La classe GridViewRowCollection prend en charge plusieurs modes d'accès aux éléments de la collection :

  • Utilisez l'indexeur Item pour récupérer directement un objet GridViewRow à un index de base zéro spécifique.

  • Utilisez la méthode GetEnumerator afin de récupérer un énumérateur pouvant être utilisé pour itérer au sein de la collection.

  • Utilisez la méthode CopyTo pour copier les éléments de la collection dans un objet System..::.Array, qui peut ensuite être utilisé pour accéder aux éléments de la collection.

Utilisez la propriété Count pour déterminer le nombre total d'éléments de la collection.

L'exemple suivant montre comment itérer au sein de la collection Rows d'un contrôle GridView et afficher les valeurs d'une colonne sur la page.

Visual Basic

<%@ Page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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  >
  <head runat="server">
    <title>GridViewRowCollection Example</title>
</head>
<body>
    <form id="form1" 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>

C#

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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  >
  <head runat="server">
    <title>GridViewRowCollection Example</title>
</head>
<body>
    <form id="form1" 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>

.NET Framework

Pris en charge dans : 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 ou ultérieur, Windows XP SP3, Windows XP SP2 Édition x64, Windows Server 2008 (installation minimale non prise en charge), Windows Server 2008 R2 (installation minimale prise en charge avec SP1 ou version ultérieure), Windows Server 2003 SP2

Le .NET Framework ne prend pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.
Tous les membres static (Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.
Contenu de la communauté   Qu'est-ce que le Contenu de la communauté ?
Ajouter du contenu RSS  Annotations
Processing
© 2012 Microsoft. Tous droits réservés. Conditions d'utilisation | Marques | Confidentialité
Page view tracker