Share via


CatalogPartCollection.Contains(CatalogPart) Méthode

Définition

Retourne une valeur indiquant si un contrôle particulier existe dans la collection.

public:
 bool Contains(System::Web::UI::WebControls::WebParts::CatalogPart ^ catalogPart);
public bool Contains (System.Web.UI.WebControls.WebParts.CatalogPart catalogPart);
member this.Contains : System.Web.UI.WebControls.WebParts.CatalogPart -> bool
Public Function Contains (catalogPart As CatalogPart) As Boolean

Paramètres

catalogPart
CatalogPart

CatalogPart qui est vérifié pour déterminer s'il est dans la collection.

Retours

Boolean

Valeur Boolean indiquant si un contrôle particulier existe dans la collection.

Exemples

L’exemple de code suivant montre comment déterminer si un contrôle particulier CatalogPart est membre d’un CatalogPartCollection objet. Pour obtenir le code complet requis pour exécuter l’exemple, consultez la section Exemple de la rubrique vue d’ensemble de la CatalogPartCollection classe.

Le code de la Button1_Click méthode crée un objet CatalogPartCollection nommé myParts. La méthode utilise la Contains méthode pour déterminer si le PageCatalogPart1 contrôle existe et, le cas échéant, récupère le contrôle et modifie une valeur de propriété.

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 

Lorsque vous chargez la page dans un navigateur, vous pouvez basculer la page en mode catalogue en sélectionnant Catalogue dans le contrôle de liste déroulante Mode d’affichage . Ajoutez le contrôle personnalisé WebPart à la page en cochérant la case en regard de celle-ci, puis en cliquant sur Ajouter. Cliquez sur Fermer pour retourner la page pour parcourir le mode. Dans le contrôle que vous venez d’ajouter, si vous cliquez sur le menu des verbes (flèche vers le bas qui apparaît dans la barre de titre), puis cliquez sur Fermer, le contrôle est supprimé de la page et ajouté au PageCatalogPart contrôle. Retournez la page en mode catalogue, puis cliquez sur le lien Catalogue de pages pour afficher le contenu du PageCatalogPart contrôle. Notez que le contrôle que vous avez fermé a été ajouté. Le fait de cliquer sur le bouton Afficher les propriétés de CatalogPart accède à l’objet CatalogPartCollection et affiche certaines propriétés des contrôles contenus CatalogPart . Cochez la case en regard du contrôle serveur contenu dans le PageCatalogPart contrôle, cliquez sur Ajouter pour l’ajouter à la page, puis sur Fermer pour retourner la page en mode Parcourir. Cliquez à nouveau sur le menu des verbes sur le contrôle, puis notez que maintenant le verbe fermé est parti. Il a été supprimé par le code de la Button1_Click méthode, lorsqu’il a utilisé la Contains méthode pour rechercher PageCatalogPart1, puis défini sa AllowClose propriété falsesur .

Remarques

La Contains méthode vous permet de déterminer si un objet particulier CatalogPart fait partie d’un CatalogPartCollection objet.

S’applique à

Voir aussi