Udostępnij za pośrednictwem


CatalogPartCollection.Item[] Właściwość

Definicja

Zwraca określony element członkowski kolekcji zgodnie z jego pozycją lub unikatowym identyfikatorem.

Przeciążenia

Item[Int32]

Pobiera lub ustawia element członkowski kolekcji na podstawie jego pozycji w kolekcji.

Item[String]

Zwraca element członkowski kolekcji na podstawie unikatowego identyfikatora ciągu.

Item[Int32]

Pobiera lub ustawia element członkowski kolekcji na podstawie jego pozycji w kolekcji.

public:
 property System::Web::UI::WebControls::WebParts::CatalogPart ^ default[int] { System::Web::UI::WebControls::WebParts::CatalogPart ^ get(int index); };
public System.Web.UI.WebControls.WebParts.CatalogPart this[int index] { get; }
member this.Item(int) : System.Web.UI.WebControls.WebParts.CatalogPart
Default Public ReadOnly Property Item(index As Integer) As CatalogPart

Parametry

index
Int32

Indeks określonego CatalogPart elementu w kolekcji.

Wartość właściwości

CatalogPart

A CatalogPart w określonym indeksie w kolekcji.

Przykłady

W poniższym przykładzie kodu pokazano, jak można uzyskać dostęp do elementu członkowskiego obiektu przy użyciu jego indeksu CatalogPartCollection . Pełny kod wymagany do uruchomienia przykładu można znaleźć w sekcji Przykład w CatalogPartCollection temacie Omówienie klasy.

Kod w metodzie Button1_Click tworzy nowy CatalogPartCollection obiekt o nazwie myParts. Należy pamiętać, że metoda używa indeksatora Item[] do pobierania informacji z pierwszego elementu członkowskiego kolekcji.

protected void Button1_Click(object sender, EventArgs e)
{
  ArrayList list = new ArrayList(2);
  list.Add(PageCatalogPart1);
  list.Add(DeclarativeCatalogPart1);
  // Pass an ICollection object to the constructor.
  CatalogPartCollection myParts = new CatalogPartCollection(list);
  foreach (CatalogPart catalog in myParts)
  {
    catalog.Description = "My " + catalog.DisplayTitle;
  }

  // Use the IndexOf property to locate a CatalogPart control.
  int PageCatalogPartIndex = myParts.IndexOf(PageCatalogPart1);
  myParts[PageCatalogPartIndex].ChromeType = PartChromeType.TitleOnly;

  // Use the Contains method to see if a CatalogPart control exists.
  if (myParts.Contains(PageCatalogPart1))
  {
    WebPart closedWebPart = null;
    WebPartDescriptionCollection descriptions = PageCatalogPart1.GetAvailableWebPartDescriptions();
    if (descriptions.Count > 0)
    {
      closedWebPart = PageCatalogPart1.GetWebPart(descriptions[0]);
      closedWebPart.AllowClose = false;
    }
  }
  
  // Use indexers to display the details of the CatalogPart controls.
  Label1.Text = String.Empty;
  Label1.Text =
    "<h3>PageCatalogPart Details</h3>" +
    "ID: " + myParts[0].ID + "<br />" +
    "Count: " + myParts[0].GetAvailableWebPartDescriptions().Count;
  Label1.Text += 
    "<h3>DeclarativeCatalogPart Details</h3>" +
    "ID: " + myParts["DeclarativeCatalogPart1"].ID + "<br />" +
    "Count: " + myParts["DeclarativeCatalogPart1"].GetAvailableWebPartDescriptions().Count;
}
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) 
    Dim list As New ArrayList(2)
    list.Add(PageCatalogPart1)
    list.Add(DeclarativeCatalogPart1)
    ' Pass an ICollection object to the constructor.
    Dim myParts As New CatalogPartCollection(list)
    Dim catalog As CatalogPart
    For Each catalog In  myParts
        catalog.Description = "My " + catalog.DisplayTitle
    Next catalog
    
    ' Use the IndexOf property to locate a CatalogPart control.
    Dim PageCatalogPartIndex As Integer = _
      myParts.IndexOf(PageCatalogPart1)
    myParts(PageCatalogPartIndex).ChromeType = PartChromeType.TitleOnly
    
    ' Use the Contains method to see if a CatalogPart control exists.
    If myParts.Contains(PageCatalogPart1) Then
        Dim closedWebPart As WebPart = Nothing
        Dim descriptions As WebPartDescriptionCollection = _
          PageCatalogPart1.GetAvailableWebPartDescriptions()
        If descriptions.Count > 0 Then
            closedWebPart = PageCatalogPart1.GetWebPart(descriptions(0))
            closedWebPart.AllowClose = False
        End If
    End If
    
    ' Use indexers to display the details of the CatalogPart controls.
    Label1.Text = String.Empty
    Label1.Text = _
      "<h3>PageCatalogPart Details</h3>" & _
      "ID: " & myParts(0).ID + "<br />" & _
      "Count: " & myParts(0).GetAvailableWebPartDescriptions().Count
    Label1.Text += _
      "<h3>DeclarativeCatalogPart Details</h3>" & _
      "ID: " & myParts("DeclarativeCatalogPart1").ID & "<br />" & _
      "Count: " & myParts("DeclarativeCatalogPart1") _
        .GetAvailableWebPartDescriptions().Count

End Sub 

Po załadowaniu strony w przeglądarce możesz przełączyć stronę do trybu wykazu, wybierając pozycję Wykaz w kontrolce listy rozwijanej Tryb wyświetlania . Kliknięcie przycisku Wyświetl właściwości elementu CatalogPart powoduje uzyskanie dostępu do CatalogPartCollection obiektu i wyświetlenie niektórych właściwości zawartych CatalogPart kontrolek. Liczba dostępnych kontrolek serwera w kontrolce PageCatalogPart jest uzyskiwana przy użyciu Item[] indeksatora w metodzie Button1_Click .

Uwagi

Item[] Indeksator umożliwia dostęp do podstawowych CatalogPart kontrolek w obiekcie według indeksu CatalogPartCollection i zmiany ich wartości właściwości lub metod wywołania.

Zobacz też

Dotyczy

Item[String]

Zwraca element członkowski kolekcji na podstawie unikatowego identyfikatora ciągu.

public:
 property System::Web::UI::WebControls::WebParts::CatalogPart ^ default[System::String ^] { System::Web::UI::WebControls::WebParts::CatalogPart ^ get(System::String ^ id); };
public System.Web.UI.WebControls.WebParts.CatalogPart this[string id] { get; }
member this.Item(string) : System.Web.UI.WebControls.WebParts.CatalogPart
Default Public ReadOnly Property Item(id As String) As CatalogPart

Parametry

id
String

Unikatowy identyfikator określonego CatalogPart elementu w kolekcji.

Wartość właściwości

CatalogPart

Pierwszy CatalogPart w kolekcji, którego identyfikator jest równy wartości id.

Przykłady

W poniższym przykładzie kodu pokazano, jak można uzyskać dostęp do elementu członkowskiego CatalogPartCollection obiektu przy użyciu jego wartości identyfikatora ciągu. Pełny kod wymagany do uruchomienia przykładu można znaleźć w sekcji Przykład w CatalogPartCollection temacie Omówienie klasy.

Kod w metodzie Button1_Click tworzy nowy CatalogPartCollection obiekt o nazwie myParts. Metoda używa indeksatora Item[] do pobierania informacji o DeclarativeCatalogPart kontrolce, która jest drugim elementem członkowskim kolekcji.

protected void Button1_Click(object sender, EventArgs e)
{
  ArrayList list = new ArrayList(2);
  list.Add(PageCatalogPart1);
  list.Add(DeclarativeCatalogPart1);
  // Pass an ICollection object to the constructor.
  CatalogPartCollection myParts = new CatalogPartCollection(list);
  foreach (CatalogPart catalog in myParts)
  {
    catalog.Description = "My " + catalog.DisplayTitle;
  }

  // Use the IndexOf property to locate a CatalogPart control.
  int PageCatalogPartIndex = myParts.IndexOf(PageCatalogPart1);
  myParts[PageCatalogPartIndex].ChromeType = PartChromeType.TitleOnly;

  // Use the Contains method to see if a CatalogPart control exists.
  if (myParts.Contains(PageCatalogPart1))
  {
    WebPart closedWebPart = null;
    WebPartDescriptionCollection descriptions = PageCatalogPart1.GetAvailableWebPartDescriptions();
    if (descriptions.Count > 0)
    {
      closedWebPart = PageCatalogPart1.GetWebPart(descriptions[0]);
      closedWebPart.AllowClose = false;
    }
  }
  
  // Use indexers to display the details of the CatalogPart controls.
  Label1.Text = String.Empty;
  Label1.Text =
    "<h3>PageCatalogPart Details</h3>" +
    "ID: " + myParts[0].ID + "<br />" +
    "Count: " + myParts[0].GetAvailableWebPartDescriptions().Count;
  Label1.Text += 
    "<h3>DeclarativeCatalogPart Details</h3>" +
    "ID: " + myParts["DeclarativeCatalogPart1"].ID + "<br />" +
    "Count: " + myParts["DeclarativeCatalogPart1"].GetAvailableWebPartDescriptions().Count;
}
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) 
    Dim list As New ArrayList(2)
    list.Add(PageCatalogPart1)
    list.Add(DeclarativeCatalogPart1)
    ' Pass an ICollection object to the constructor.
    Dim myParts As New CatalogPartCollection(list)
    Dim catalog As CatalogPart
    For Each catalog In  myParts
        catalog.Description = "My " + catalog.DisplayTitle
    Next catalog
    
    ' Use the IndexOf property to locate a CatalogPart control.
    Dim PageCatalogPartIndex As Integer = _
      myParts.IndexOf(PageCatalogPart1)
    myParts(PageCatalogPartIndex).ChromeType = PartChromeType.TitleOnly
    
    ' Use the Contains method to see if a CatalogPart control exists.
    If myParts.Contains(PageCatalogPart1) Then
        Dim closedWebPart As WebPart = Nothing
        Dim descriptions As WebPartDescriptionCollection = _
          PageCatalogPart1.GetAvailableWebPartDescriptions()
        If descriptions.Count > 0 Then
            closedWebPart = PageCatalogPart1.GetWebPart(descriptions(0))
            closedWebPart.AllowClose = False
        End If
    End If
    
    ' Use indexers to display the details of the CatalogPart controls.
    Label1.Text = String.Empty
    Label1.Text = _
      "<h3>PageCatalogPart Details</h3>" & _
      "ID: " & myParts(0).ID + "<br />" & _
      "Count: " & myParts(0).GetAvailableWebPartDescriptions().Count
    Label1.Text += _
      "<h3>DeclarativeCatalogPart Details</h3>" & _
      "ID: " & myParts("DeclarativeCatalogPart1").ID & "<br />" & _
      "Count: " & myParts("DeclarativeCatalogPart1") _
        .GetAvailableWebPartDescriptions().Count

End Sub 

Po załadowaniu strony w przeglądarce możesz przełączyć stronę do trybu wykazu, wybierając pozycję Wykaz w kontrolce listy rozwijanej Tryb wyświetlania . Kliknięcie przycisku Wyświetl właściwości elementu CatalogPart powoduje uzyskanie dostępu do CatalogPartCollection obiektu i wyświetlenie niektórych właściwości zawartych CatalogPart kontrolek. Liczba dostępnych kontrolek serwera w kontrolce DeclarativeCatalogPart jest uzyskiwana przy użyciu Item[] indeksatora w metodzie Button1_Click .

Uwagi

Indeksator Item[] umożliwia dostęp do podstawowych CatalogPart kontrolek w CatalogPartCollection obiekcie przy użyciu identyfikatora ciągu. CatalogPartCollection Mimo że obiekt jest tylko do odczytu, można zmienić wartości właściwości lub wywołać metody na podstawowych kontrolkach, do których uzyskuje dostęp indeksator.

Zobacz też

Dotyczy