Aracılığıyla paylaş


GridViewRowCollection Sınıf

Tanım

Denetimdeki GridViewRow bir nesne koleksiyonunu GridView temsil eder.

public ref class GridViewRowCollection : System::Collections::ICollection
public class GridViewRowCollection : System.Collections.ICollection
type GridViewRowCollection = class
    interface ICollection
    interface IEnumerable
Public Class GridViewRowCollection
Implements ICollection
Devralma
GridViewRowCollection
Uygulamalar

Örnekler

Aşağıdaki örnek, bir GridView denetimin Rows koleksiyonunda yinelemeyi ve sayfadaki bir sütunun değerlerini görüntülemeyi gösterir.


<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
  <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>

<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
  <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>

Açıklamalar

GridViewRowCollection sınıfı, bir denetimdeki GridView nesne koleksiyonunu GridViewRow depolamak ve yönetmek için kullanılır. Denetimdeki GridView her satır bir GridViewRow nesneyle temsil edilir. Denetim, GridView tüm veri satırlarını koleksiyonda Rows depolar.

sınıfı koleksiyondaki GridViewRowCollection öğelere erişmenin çeşitli yollarını destekler:

  • Belirli bir sıfır tabanlı dizindeki Item[] bir GridViewRow nesneyi doğrudan almak için dizin oluşturucuyu kullanın.

  • GetEnumerator Yöntemini kullanarak koleksiyonda yinelemek için kullanılabilecek bir numaralandırıcı alın.

  • CopyTo Koleksiyondaki öğeleri bir System.Array nesneye kopyalamak için yöntemini kullanın; daha sonra koleksiyondaki öğelere erişmek için kullanılabilir.

Koleksiyondaki öğelerin toplam sayısını belirlemek için özelliğini kullanın Count

Oluşturucular

Name Description
GridViewRowCollection(ArrayList)

Belirtilen GridViewRowCollection nesneyi kullanarak sınıfın ArrayList yeni bir örneğini başlatır.

Özellikler

Name Description
Count

Nesnedeki GridViewRowCollection öğe sayısını alır.

IsReadOnly

Nesnedeki GridViewRowCollection satırların değiştirilip değiştirilemeyeceğini belirten bir değer alır.

IsSynchronized

Nesnenin GridViewRowCollection eşitlenip eşitlenmediğini belirten bir değer alır (iş parçacığı güvenli).

Item[Int32]

GridViewRow Nesneyi belirtilen dizinde alır.

SyncRoot

Koleksiyona erişimi eşitlemek için kullanılan nesneyi alır.

Yöntemler

Name Description
CopyTo(GridViewRow[], Int32)

Nesnedeki belirtilen Array dizinden başlayarak, bu GridViewRowCollection öğedeki tüm öğeleri belirtilen nesneye Array kopyalar.

Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetEnumerator()

içindeki GridViewRowCollectiontüm GridViewRow nesneleri içeren bir numaralandırıcı döndürür.

GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetType()

Geçerli örneğin Type alır.

(Devralındığı yer: Object)
MemberwiseClone()

Geçerli Objectbasit bir kopyasını oluşturur.

(Devralındığı yer: Object)
ToString()

Geçerli nesneyi temsil eden bir dize döndürür.

(Devralındığı yer: Object)

Belirtik Arabirim Kullanımları

Name Description
ICollection.CopyTo(Array, Int32)

Bu üyenin açıklaması için bkz CopyTo(Array, Int32). .

Uzantı Metotları

Name Description
AsParallel(IEnumerable)

Sorgunun paralelleştirilmesini etkinleştirir.

AsQueryable(IEnumerable)

bir IEnumerable öğesine IQueryabledönüştürür.

Cast<TResult>(IEnumerable)

öğesinin IEnumerable öğelerini belirtilen türe yazar.

OfType<TResult>(IEnumerable)

Belirtilen türe göre bir IEnumerable öğesinin öğelerini filtreler.

Şunlara uygulanır

Ayrıca bkz.