DetailsViewRowCollection Klasa

Definicja

Reprezentuje kolekcję DetailsViewRow obiektów w kontrolce DetailsView .

public ref class DetailsViewRowCollection : System::Collections::ICollection
public class DetailsViewRowCollection : System.Collections.ICollection
type DetailsViewRowCollection = class
    interface ICollection
    interface IEnumerable
Public Class DetailsViewRowCollection
Implements ICollection
Dziedziczenie
DetailsViewRowCollection
Implementuje

Przykłady

W poniższym przykładzie kodu pokazano, jak iterować obiekty DetailsViewRow w Rows kolekcji kontrolki DetailsView . Wartość każdego wiersza jest następnie wyświetlana na stronie.


<%@ 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 SubmitButton_Click(Object sender, EventArgs e)
  {

    // Use the Count property to determine whether the
    // Rows collection contains any item.
    if (ItemDetailsView.Rows.Count > 0)
    {
      // Iterate through the Rows collection and display
      // the value of each field.
      MessageLabel.Text = "The row values are: <br/><br/>";

      foreach (DetailsViewRow row in ItemDetailsView.Rows)
      {
        // Use the Text property to access the value of 
        // each cell. In this example, the cells in the 
        // first column (index 0) contains the field names, 
        // while the cells in the second column (index 1)
        // contains the field value. 
        MessageLabel.Text += row.Cells[0].Text + " = " +
          row.Cells[1].Text + "<br/>";
      }
    }
    else
    {
      MessageLabel.Text = "No items.";
    }

  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsViewRowCollection Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>DetailsViewRowCollection Example</h3>
  
      <asp:detailsview id="ItemDetailsView"
        datasourceid="DetailsViewSource"
        allowpaging="true"
        autogeneraterows="false" 
        runat="server">
        <fields>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID"/>
          <asp:boundfield datafield="CompanyName"
            headertext="Company Name"/>
          <asp:boundfield datafield="Address"
            headertext="Address"/>
          <asp:boundfield datafield="City"
            headertext="City"/>
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"
            headertext="Country"/>
        </fields>
      </asp:detailsview>
      
      <br/>
      
      <asp:button id="SubmitButton" 
        text="Display Row Values"
        onclick="SubmitButton_Click"
        runat="server"/>
        
      <br/><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="DetailsViewSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], 
          [City], [PostalCode], [Country] From [Customers]"
        connectionstring=
          "<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>  
  
    </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 SubmitButton_Click(ByVal sender As Object, ByVal e As EventArgs)
 
    ' Use the Count property to determine whether the
    ' Rows collection contains any item.
    If ItemDetailsView.Rows.Count > 0 Then
    
      ' Iterate through the Rows collection and display
      ' the value of each field.
      MessageLabel.Text = "The row values are: <br/><br/>"
    
      Dim row As DetailsViewRow
    
      For Each row In ItemDetailsView.Rows
    
        ' Use the Text property to access the value of 
        ' each cell. In this example, the cells in the 
        ' first column (index 0) contains the field names, 
        ' while the cells in the second column (index 1)
        ' contains the field value. 
        MessageLabel.Text &= row.Cells(0).Text & " = " & _
          row.Cells(1).Text & "<br/>"
    
      Next
    
    Else
      
      MessageLabel.Text = "No items."
    
    End If
    
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>DetailsViewRowCollection Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>DetailsViewRowCollection Example</h3>
  
      <asp:detailsview id="ItemDetailsView"
        datasourceid="DetailsViewSource"
        allowpaging="true"
        autogeneraterows="false" 
        runat="server">
        <fields>
          <asp:boundfield datafield="CustomerID"
            headertext="Customer ID"/>
          <asp:boundfield datafield="CompanyName"
            headertext="Company Name"/>
          <asp:boundfield datafield="Address"
            headertext="Address"/>
          <asp:boundfield datafield="City"
            headertext="City"/>
          <asp:boundfield datafield="PostalCode"
            headertext="ZIP Code"/>
          <asp:boundfield datafield="Country"
            headertext="Country"/>
        </fields>
      </asp:detailsview>
      
      <br/>
      
      <asp:button id="SubmitButton" 
        text="Display Row Values"
        onclick="SubmitButton_Click"
        runat="server"/>
        
      <br/><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="DetailsViewSource"
        selectcommand="Select [CustomerID], [CompanyName], [Address], 
          [City], [PostalCode], [Country] From [Customers]"
        connectionstring=
          "<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>  
  
    </form>
  </body>
</html>

Uwagi

Klasa DetailsViewRowCollection służy do przechowywania kolekcji DetailsViewRow obiektów w kontrolce DetailsView i zarządzania nimi. Każdy wiersz w kontrolce DetailsView jest reprezentowany DetailsViewRow przez obiekt. Kontrolka DetailsViewDetailsViewRowCollection używa klasy dla jej Rows właściwości.

Uwaga

Właściwość Rows zawiera tylko wiersze danych. Aby uzyskać dostęp do wiersza nagłówka, wiersza stopki, górnego wiersza pager i dolnego wiersza pager, użyj HeaderRowodpowiednio właściwości , FooterRow, TopPagerRowi BottomPagerRow .

Klasa DetailsViewRowCollection obsługuje kilka sposobów uzyskiwania dostępu do elementów w kolekcji:

  • Użyj indeksatora Item[] , aby bezpośrednio pobrać DetailsViewRow obiekt z kolekcji w określonym indeksie zerowym.

  • GetEnumerator Użyj metody , aby pobrać moduł wyliczający, którego można użyć do iteracji po kolekcji.

  • CopyTo Użyj metody , aby skopiować elementy w kolekcji do tablicy, która następnie może służyć do uzyskiwania dostępu do elementów w kolekcji.

Aby określić całkowitą liczbę elementów w kolekcji, użyj Count właściwości .

Konstruktory

DetailsViewRowCollection(ArrayList)

Inicjuje DetailsViewRowCollection nowe wystąpienie klasy przy użyciu określonego ArrayList obiektu.

Właściwości

Count

Pobiera liczbę elementów w DetailsViewRowCollection obiekcie.

IsReadOnly

Pobiera wartość wskazującą, czy wiersze w DetailsViewRowCollection obiekcie można modyfikować.

IsSynchronized

Pobiera wartość wskazującą, czy DetailsViewRowCollection obiekt jest synchronizowany (bezpieczny wątek).

Item[Int32]

DetailsViewRow Pobiera obiekt z kolekcji w określonym indeksie.

SyncRoot

Pobiera obiekt używany do synchronizowania dostępu do kolekcji.

Metody

CopyTo(DetailsViewRow[], Int32)

Kopiuje wszystkie elementy z tego DetailsViewRowCollection obiektu do określonego Array obiektu, począwszy od określonego indeksu w obiekcie Array.

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetEnumerator()

Zwraca moduł wyliczający zawierający wszystkie DetailsViewRow obiekty w DetailsViewRowCollection obiekcie .

GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Jawne implementacje interfejsu

ICollection.CopyTo(Array, Int32)

Kopiuje wszystkie elementy z tego DetailsViewRowCollection obiektu do określonego Array obiektu, począwszy od określonego indeksu w obiekcie Array.

Metody rozszerzania

Cast<TResult>(IEnumerable)

Rzutuje elementy obiektu IEnumerable na określony typ.

OfType<TResult>(IEnumerable)

Filtruje elementy IEnumerable elementu na podstawie określonego typu.

AsParallel(IEnumerable)

Umożliwia równoległość zapytania.

AsQueryable(IEnumerable)

Konwertuje element IEnumerable na .IQueryable

Dotyczy

Zobacz też