WebPartZoneCollection 构造函数

定义

初始化 WebPartZoneCollection 类的新实例。Initializes a new instance of the WebPartZoneCollection class.

重载

WebPartZoneCollection()

初始化 WebPartZoneCollection 类的空实例。Initializes an empty instance of the WebPartZoneCollection class.

WebPartZoneCollection(ICollection)

通过传入 WebPartZoneCollection 对象的集合来初始化 WebPartZone 类的实例。Initializes an instance of the WebPartZoneCollection class by passing in a collection of WebPartZone objects.

注解

此构造函数由WebPartManager控件、Web 部件控件集中的其他控件或自定义开发人员代码使用, 以创建 Web 部件页上存在的WebPartZone控件的只读集合。 WebPartZoneCollectionThe 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()

初始化 WebPartZoneCollection 类的空实例。Initializes an empty instance of the WebPartZoneCollection class.

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

注解

控件在其自己的构造函数中使用此构造函数来初始化 Web 部件页WebPartZoneCollection的类的新实例。 WebPartManagerThe WebPartManager control uses this constructor within its own constructor to initialize a new instance of the WebPartZoneCollection class for a Web Parts page.

另请参阅

WebPartZoneCollection(ICollection)

通过传入 WebPartZoneCollection 对象的集合来初始化 WebPartZone 类的实例。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)

参数

webPartZones
ICollection

ICollection 对象的 WebPartZoneAn ICollection of WebPartZone objects.

例外

区域的集合为 nullThe collection of zones is null.

集合中的某个对象是 null,或其类型不是 WebPartZoneOne of the objects in the collection is null or is not of type WebPartZone.

示例

下面的代码示例演示如何使用WebPartZoneCollection构造函数。The following code example demonstrates the use of the WebPartZoneCollection constructor. 该示例的完整代码位于WebPartZoneCollection类概述的 "示例" 部分。The complete code for the example is found in the Example section of the WebPartZoneCollection class overview.

请注意, 在下面的代码部分中, 它通过WebPartZoneCollection检索Zones属性的值将对象分配给变量。In the following section of code, notice that it assigns a WebPartZoneCollection object to a variable by retrieving the value of the Zones property. 如果需要, Zones您可以创建一个WebPartZoneBase对象数组, 其中包含该页上所有区域的子集, 并将该数组分配给新WebPartZoneCollection的对象。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.

注解

如果要创建WebPartZone对象的自定义集合以对其执行编程操作, 请使用构造函数。WebPartZoneCollectionUse the WebPartZoneCollection constructor when you want to create a custom collection of WebPartZone objects to carry out programmatic operations on them. 例如, 你可以访问Zones属性并在 Web 部件页上创建WebPartZone对象的子集WebPartZoneCollection , 并将其分配给对象, 然后在子控件上执行操作, 或仅对此子集的各个属性执行操作分区.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.

另请参阅

适用于