GridViewRowCollection 클래스

정의

GridViewRow 컨트롤에 있는 GridView 개체의 컬렉션을 나타냅니다.

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
상속
GridViewRowCollection
구현

예제

다음 예제에서는 반복 하는 방법에 설명 합니다 Rows 의 컬렉션을 GridView 제어 하 고 페이지의 열 값을 표시 합니다.


<%@ 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>

설명

GridViewRowCollection 클래스를 저장 및 컬렉션을 관리 하는 데 사용 됩니다 GridViewRow 개체를 GridView 제어 합니다. 각 행을 GridView 컨트롤은 표현는 GridViewRow 개체입니다. GridView 컨트롤에 해당 데이터 행의 모든 저장 된 Rows 컬렉션입니다.

GridViewRowCollection 클래스는 컬렉션의 항목에 액세스 하는 여러 방법을 지원 합니다.

  • 사용 합니다 Item[] 인덱서를 직접 검색 하는 GridViewRow 특정 인덱스에 있는 개체입니다.

  • 사용 된 GetEnumerator 메서드 컬렉션을 반복 하는 데 사용할 수 있는 열거자를 검색 합니다.

  • 사용 합니다 CopyTo 컬렉션의 항목을 복사 하는 메서드는 System.Array 개체를 컬렉션의 항목에 액세스를 사용할 수 있습니다.

컬렉션에서 항목의 총 수를 확인 하려면 사용 된 Count 속성

생성자

GridViewRowCollection(ArrayList)

지정된 ArrayList 개체를 사용하여 GridViewRowCollection 클래스의 새 인스턴스를 초기화합니다.

속성

Count

GridViewRowCollection 개체의 항목 수를 가져옵니다.

IsReadOnly

GridViewRowCollection 개체의 행을 수정할 수 있는지 여부를 나타내는 값을 가져옵니다.

IsSynchronized

GridViewRowCollection 개체가 동기화되어 스레드로부터 안전한지 여부를 나타내는 값을 가져옵니다.

Item[Int32]

지정된 인덱스의 GridViewRow 개체를 가져옵니다.

SyncRoot

컬렉션에 대한 액세스 권한을 동기화하는 데 사용된 개체를 가져옵니다.

메서드

CopyTo(GridViewRow[], Int32)

GridViewRowCollection 개체의 지정된 인덱스부터 시작하여 이 Array에서 지정된 Array 개체로 모든 항목을 복사합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetEnumerator()

GridViewRow의 모든 GridViewRowCollection 개체를 포함하는 열거자를 반환합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

ICollection.CopyTo(Array, Int32)

이 멤버에 대한 설명은 CopyTo(Array, Int32)를 참조하세요.

확장 메서드

Cast<TResult>(IEnumerable)

IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.

OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.

AsParallel(IEnumerable)

쿼리를 병렬화할 수 있도록 합니다.

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상

추가 정보