WebPartZoneCollection 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 WebPartZoneCollection 类的新实例。
重载
WebPartZoneCollection() |
初始化 WebPartZoneCollection 类的空实例。 |
WebPartZoneCollection(ICollection) |
通过传入 WebPartZoneCollection 对象的集合来初始化 WebPartZone 类的实例。 |
注解
该WebPartZoneCollection构造函数由WebPartManager控件、Web 部件控件集中的其他控件或自定义开发人员代码使用,以创建Web 部件页上存在的控件的WebPartZone只读集合。
WebPartZoneCollection()
初始化 WebPartZoneCollection 类的空实例。
public:
WebPartZoneCollection();
public WebPartZoneCollection ();
Public Sub New ()
注解
控件WebPartManager在其自己的构造函数中使用此构造函数初始化Web 部件页的WebPartZoneCollection类的新实例。
另请参阅
适用于
WebPartZoneCollection(ICollection)
通过传入 WebPartZoneCollection 对象的集合来初始化 WebPartZone 类的实例。
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 对象的 WebPartZone。
例外
区域的集合为 null
。
集合中的某个对象是 null
,或其类型不是 WebPartZone。
示例
下面的代码示例演示了构造函数的使用 WebPartZoneCollection 。 示例的完整代码位于类概述的 WebPartZoneCollection “示例”部分中。
在代码的以下部分中,请注意,它通过检索Zones属性值将对象分配给WebPartZoneCollection变量。 如果需要,而不是从 Zones 属性分配所有区域,则可以创建包含页面上所有区域子集的对象数组 WebPartZoneBase ,并将数组分配给新 WebPartZoneCollection 对象。
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
创建集合后,可以轻松循环访问集合,并对所有包含区域或其内容执行操作。 若要执行示例代码,请在浏览器中加载页面,然后单击每个区域中的 “切换谓词呈现模式 ”按钮。 这替代了如何呈现区域中包含的每个服务器控件的标题栏中的谓词。 谓词可以出现在下拉菜单中,也可以直接显示为标题栏中的链接。
注解
WebPartZoneCollection如果要创建自定义对象的集合WebPartZone以对其执行编程操作,请使用构造函数。 例如,你可以访问Zones该属性并在Web 部件页上创建对象子集WebPartZone,将其WebPartZoneCollection分配给对象,然后对子控件或仅该区域子集的各种属性执行操作。