CatalogPartCollection.Item Property (String)


Returns a member of the collection based on a unique string identifier.

Namespace:   System.Web.UI.WebControls.WebParts
Assembly:  System.Web (in System.Web.dll)

public CatalogPart this[
	string id
] { get; }


Type: System.String

The unique identifier for a particular CatalogPart in a collection.

Property Value

Type: System.Web.UI.WebControls.WebParts.CatalogPart

The first CatalogPart in the collection whose ID equals the value of id.

The Item indexer allows you to access the underlying CatalogPart controls in a CatalogPartCollection object by use of a string identifier. Although the CatalogPartCollection object is read-only, you can change the property values or call methods on the underlying controls accessed by the indexer.

The following code example demonstrates how you can access a member of a CatalogPartCollection object using its string ID value. For the full code required to run the example, see the Example section of the CatalogPartCollection class overview topic.

The code in the Button1_Click method creates a new CatalogPartCollection object named myParts. The method uses the Item indexer to retrieve information about the DeclarativeCatalogPart control, which is the second member of the collection.

protected void Button1_Click(object sender, EventArgs e)
  ArrayList list = new ArrayList(2);
  // 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;

When you load the page in a browser, you can switch the page into catalog mode by selecting Catalog in the Display Mode drop-down list control. Clicking the Display CatalogPart Properties button accesses the CatalogPartCollection object and displays certain properties of the contained CatalogPart controls. The count of available server controls within the DeclarativeCatalogPart control is obtained by using the Item indexer in the Button1_Click method.

.NET Framework
Available since 2.0
Return to top