Bewerken

Delen via


CatalogPartCollection Constructors

Definition

Initializes a new instance of the CatalogPartCollection class.

Overloads

CatalogPartCollection()

Initializes a new, empty instance of the CatalogPartCollection class.

CatalogPartCollection(ICollection)

Initializes a new instance of the CatalogPartCollection class by passing in an ICollection collection of CatalogPart controls.

CatalogPartCollection(CatalogPartCollection, ICollection)

Initializes a new instance of the CatalogPartCollection class by passing in an ICollection collection of the existing CatalogPart controls in a zone, and an additional collection of controls.

Remarks

The CatalogZoneBase zone that contains CatalogPart controls is typically the control that creates a CatalogPartCollection object, through the CreateCatalogParts method. However, you can also create your own CatalogPartCollection object for other programmatic purposes.

CatalogPartCollection()

Initializes a new, empty instance of the CatalogPartCollection class.

public:
 CatalogPartCollection();
public CatalogPartCollection ();
Public Sub New ()

Remarks

The CatalogPartCollection constructor initializes an empty instance of the CatalogPartCollection class. This overload of the constructor is used internally by the CatalogZone class in its CreateCatalogParts method to create an empty collection object. The zone then creates instances of all the CatalogPart controls declared in the child zone template, and uses an internal method of the collection to add them.

You cannot use this overload of the CatalogPartCollection constructor to create a new instance of a CatalogPartCollection and add CatalogPart controls to it. You must use one of the other overloads for the CatalogPartCollection constructor instead.

See also

Applies to

CatalogPartCollection(ICollection)

Initializes a new instance of the CatalogPartCollection class by passing in an ICollection collection of CatalogPart controls.

public:
 CatalogPartCollection(System::Collections::ICollection ^ catalogParts);
public CatalogPartCollection (System.Collections.ICollection catalogParts);
new System.Web.UI.WebControls.WebParts.CatalogPartCollection : System.Collections.ICollection -> System.Web.UI.WebControls.WebParts.CatalogPartCollection
Public Sub New (catalogParts As ICollection)

Parameters

catalogParts
ICollection

An ICollection of CatalogPart controls.

Examples

The following code example demonstrates how you can create a custom CatalogPartCollection, and perform a batch operation to change the individual CatalogPart controls in the collection even though it is read-only. 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 an ArrayList object, adds the two CatalogPart controls in the page to the object, and then creates a new CatalogPartCollection object using the CatalogPartCollection constructor. It also demonstrates how you can make batch changes to the underlying CatalogPart controls, even though the collection itself is read-only. The code loops through the collection, updating the Description property of each control.

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 

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. Also, if you position your mouse pointer over the title text within the border of the DeclarativeCatalogPart control, you can see the new description text that was added to the control when you clicked the button (the description appears in a ToolTip). If you click the Page Catalog link to display the PageCatalogPart control, you will find that it also has an updated description.

Remarks

The CatalogPartCollection constructor initializes an instance of the CatalogPartCollection class and passes in a collection of CatalogPart controls. This is one overload of the CatalogPartCollection constructor that you can use to create a new CatalogPartCollection object and add CatalogPart controls to it.

Although the CatalogPartCollection instance created by the constructor is read-only, you can still access the individual CatalogPart controls in the collection programmatically and call their properties and methods.

One common scenario for using this constructor would be if you want to perform some batch operation on an entire set of CatalogPart controls, such as changing the content, appearance, or position of a related group of items.

See also

Applies to

CatalogPartCollection(CatalogPartCollection, ICollection)

Initializes a new instance of the CatalogPartCollection class by passing in an ICollection collection of the existing CatalogPart controls in a zone, and an additional collection of controls.

public:
 CatalogPartCollection(System::Web::UI::WebControls::WebParts::CatalogPartCollection ^ existingCatalogParts, System::Collections::ICollection ^ catalogParts);
public CatalogPartCollection (System.Web.UI.WebControls.WebParts.CatalogPartCollection existingCatalogParts, System.Collections.ICollection catalogParts);
new System.Web.UI.WebControls.WebParts.CatalogPartCollection : System.Web.UI.WebControls.WebParts.CatalogPartCollection * System.Collections.ICollection -> System.Web.UI.WebControls.WebParts.CatalogPartCollection
Public Sub New (existingCatalogParts As CatalogPartCollection, catalogParts As ICollection)

Parameters

existingCatalogParts
CatalogPartCollection

An ICollection of existing CatalogPart controls in a zone.

catalogParts
ICollection

An ICollection of additional CatalogPart controls.

See also

Applies to