Edit

Kongsi melalui


WebPartZoneCollection Constructors

Definition

Initializes a new instance of the WebPartZoneCollection class.

Overloads

WebPartZoneCollection()

Initializes an empty instance of the WebPartZoneCollection class.

WebPartZoneCollection(ICollection)

Initializes an instance of the WebPartZoneCollection class by passing in a collection of WebPartZone objects.

Remarks

The WebPartZoneCollection constructor is used by the WebPartManager control, by other controls in the Web Parts control set, or by custom developer code, to create a read-only collection of the WebPartZone controls that exist on a Web Parts page.

WebPartZoneCollection()

Initializes an empty instance of the WebPartZoneCollection class.

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

Remarks

The WebPartManager control uses this constructor within its own constructor to initialize a new instance of the WebPartZoneCollection class for a Web Parts page.

See also

Applies to

WebPartZoneCollection(ICollection)

Initializes an instance of the WebPartZoneCollection class by passing in a collection of WebPartZone objects.

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

Parameters

webPartZones
ICollection

An ICollection of WebPartZone objects.

Exceptions

The collection of zones is null.

One of the objects in the collection is null or is not of type WebPartZone.

Examples

The following code example demonstrates the use of the WebPartZoneCollection constructor. The complete code for the example is found in the Example section of the WebPartZoneCollection class overview.

In the following section of code, notice that it assigns a WebPartZoneCollection object to a variable by retrieving the value of the Zones property. If you wanted, rather than assigning all the zones from the Zones property, you could create an array of WebPartZoneBase objects containing a subset of all the zones on the page, and assign the array to a new WebPartZoneCollection object.

protected void Button5_Click(object sender, EventArgs e)
{
  Label1.Text = String.Empty;

  WebPartZoneCollection zoneCollection = mgr.Zones;
  foreach (WebPartZone zone in zoneCollection)
  {

    if (zone.WebPartVerbRenderMode == WebPartVerbRenderMode.Menu)
      zone.WebPartVerbRenderMode = WebPartVerbRenderMode.TitleBar;
    else
      zone.WebPartVerbRenderMode = WebPartVerbRenderMode.Menu;
  }
}
Protected Sub Button5_Click(ByVal sender As Object, ByVal e As EventArgs)
  Label1.Text = String.Empty

  Dim zoneCollection As WebPartZoneCollection = mgr.Zones
  Dim zone As WebPartZone
  For Each zone In zoneCollection
    If zone.WebPartVerbRenderMode = WebPartVerbRenderMode.Menu Then
      zone.WebPartVerbRenderMode = WebPartVerbRenderMode.TitleBar
    Else
      zone.WebPartVerbRenderMode = WebPartVerbRenderMode.Menu
    End If
  Next zone

End Sub

After the collection is created, you can easily iterate through the collection and perform operations on all the contained zones or their contents. To execute the example code, load the page in a browser, and click the Toggle Verb Render Mode button on each zone. This alternates how the verbs in the title bar of each server control contained in a zone are rendered. The verbs can appear in a drop-down menu, or directly as links in the title bar.

Remarks

Use the WebPartZoneCollection constructor when you want to create a custom collection of WebPartZone objects to carry out programmatic operations on them. For example, you could access the Zones property and create a subset of WebPartZone objects on a Web Parts page, assigning them to a WebPartZoneCollection object, and then carry out operations on the child controls or various properties of only that subset of zones.

See also

Applies to