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 Example 區段中。
在下列程式碼區段中,請注意它會藉由擷取 屬性的值 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 物件,然後在子控制項或只有該區域子集的各種屬性上執行作業。