EditorPartCollection Constructor (ICollection)


Initializes a new instance of the EditorPartCollection class by passing in an ICollection collection of EditorPart controls.

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

public EditorPartCollection(
	ICollection editorParts


Type: System.Collections.ICollection

An ICollection of EditorPart controls.

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

Even though the EditorPartCollection instance created by the constructor is read-only, you can still access the individual EditorPart controls in the collection programmatically and call their properties and methods.

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

Another common scenario for using the EditorPartCollection constructor is developing custom EditorPart controls that you want to associate with a server control, so that users can edit custom properties on your control. In this scenario, your server control must implement the IWebEditable interface, and as part of that task, it must implement the CreateEditorParts method. In that method, to enable the custom EditorPart controls to edit your server control, you must add the EditorPart controls to an ICollection instance, such as an ArrayList object. Then you can pass the collection of EditorPart controls to the EditorPartCollection constructor to create a new EditorPartCollection object, which the EditorZoneBase zone uses to set up all the controls and begin the editing process.

The following code example demonstrates how to create a custom EditorPartCollection and, even though the collection is read-only, still perform a batch operation to change the individual EditorPart controls in the collection. For the full code required to run the example, see the Example section of the EditorPartCollection class overview.

The code in the Button1_Click event creates an ArrayList object, adds two of the three EditorPart controls in the page to the object, and then creates a new EditorPartCollection object using the EditorPartCollection constructor. It also demonstrates how you can make changes to the underlying EditorPart controls, even though the collection is read-only.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

  protected void Button1_Click(object sender, EventArgs e)
    ArrayList list = new ArrayList(2);
    // Pass an ICollection object to the constructor.
    EditorPartCollection myParts = new EditorPartCollection(list);
    foreach (EditorPart editor in myParts)
      editor.BackColor = System.Drawing.Color.LightBlue;
      editor.Description = "My " + editor.DisplayTitle + " editor.";

    // Use the IndexOf property to locate an EditorPart control.
    int propertyGridPart = myParts.IndexOf(PropertyGridEditorPart1);
    myParts[propertyGridPart].ChromeType = PartChromeType.TitleOnly;

    // Use the Contains method to see if an EditorPart exists.
      LayoutEditorPart1.BackColor = System.Drawing.Color.LightYellow;

    // Use the CopyTo method to create an array of EditorParts.
    EditorPart[] partArray = new EditorPart[3];
    partArray[0] = LayoutEditorPart1;
    Label1.Text = "<h3>EditorParts in Custom Array</h3>";
    foreach (EditorPart ePart in partArray)
      Label1.Text += ePart.Title + "<br />";



You can load the page in a browser and switch the page into edit mode by selecting Edit in the Display Mode drop-down list control. You can click the verbs menu (the downward arrow) in the title bar of the TextDisplayWebPart control, and click Edit to edit the control. When the editing user interface (UI) is visible, you can see all the EditorPart controls. You click the Create EditorPartCollection button to see the effects on the two EditorPart controls that are added to the EditorPartCollection object.

.NET Framework
Available since 2.0
Return to top