WebPartZoneCollection クラス
アセンブリ: System.Web (system.web.dll 内)


WebPartZoneCollection クラスには、Web パーツ ページに存在する WebPartZone コントロールのコレクションが含まれます。主に WebPartManager コントロールによって、すべてのゾーンの追跡および管理に使用されます。WebPartManager コントロールは、ページ上のゾーンのコレクションへの参照を、その読み取り専用の Zones プロパティに保持します。
WebPartZoneCollection クラスは、複数のゾーンまたはその内容に対して同時に操作を実行する場合、または特定のゾーンを検索してその内容を確認または変更する場合に便利です。ゾーン自体のコレクションは読み取り専用で、コレクション オブジェクト自体のサイズは変更できませんが、コレクション内の個別のゾーンへの参照を取得することはできます。また、個別のゾーン オブジェクトへの参照を保持している場合はそのプロパティ値を変更できます。
WebPartZoneCollection クラスには、2 つのコンストラクタがあります。1 つ目の WebPartZoneCollection は、新しい WebPartZoneCollection の空のインスタンスを初期化するだけです。2 つ目の WebPartZoneCollection(ICollection) は、ゾーンの既存のコレクションを渡すことによってコレクションを初期化します。
WebPartZoneCollection クラスには、Item プロパティが含まれています。このプロパティでは、文字列識別子を渡すことによってコレクション内の WebPartZone コントロールを検索できます。ゾーンを検索するには、文字列識別子と WebPartZoneBase ゾーンの ID プロパティの値が照合されます。
WebPartZoneCollection クラスには、その内容の確認またはアクセスに便利なメソッドも複数あります。Contains メソッドは、特定のゾーンがコレクションに存在するかどうかを判断します。CopyTo メソッドは、コレクションを WebPartZoneBase オブジェクトの配列にコピーします。最後に、IndexOf メソッドは、コレクション内の特定のゾーンのインデックスを返します。

WebPartZoneCollection クラスの使用方法を示すコード例を次に示します。コード例は、3 つの部分で構成されます。2 つがコード セクション、残りが例の実行方法の説明です。
コード例の最初の部分は、それぞれにサーバー コントロールを 1 つ含む 3 つの WebPartZone コントロールがある Web ページです。これらのサーバー コントロールはすべて標準の ASP.NET コントロールですが、WebPartZone ゾーン内に配置されているので、実行時には WebPart コントロールとして機能できます。
<%@ Page Language="vb" Codefile="webpartzonecollection_overview.vb" Inherits="webpartzonecollection_overview" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html > <head id="Head1" runat="server"> <title>WebPartZoneCollection Demo</title> </head> <body> <form id="form1" runat="server"> <div> <asp:WebPartManager ID="mgr" runat="server" /> <asp:Table ID="Table1" runat="server"> <asp:TableRow> <asp:TableCell> <asp:Label ID="lblZone1" runat="server" Font-Bold="true"> WebPartZone1 Contents </asp:Label> <asp:WebPartZone ID="WebPartZone1" runat="server" Width="230"> <ZoneTemplate> <asp:BulletedList ID="BulletedList1" Runat="server" DisplayMode="HyperLink" Title="Favorite Links" CatalogIconImageUrl="Mine.gif"> <asp:ListItem Value="http://msdn.microsoft.com"> MSDN </asp:ListItem> <asp:ListItem Value="http://www.asp.net"> ASP.NET </asp:ListItem> <asp:ListItem Value="http://www.msn.com"> MSN </asp:ListItem> </asp:BulletedList> </ZoneTemplate> </asp:WebPartZone> <div> <asp:Label ID="lblZone2" runat="server" Font-Bold="true"> WebPartZone2 Contents </asp:Label> </div> <asp:WebPartZone ID="WebPartZone2" runat="server" Width="230"> <ZoneTemplate> <asp:Calendar ID="Calendar1" runat="server" Title="My Calendar" /> </ZoneTemplate> </asp:WebPartZone> </asp:TableCell> <asp:TableCell VerticalAlign="top"> <asp:Label ID="lblZone3" runat="server" Font-Bold="true"> WebPartZone3 Contents </asp:Label> <asp:WebPartZone ID="WebPartZone3" runat="server"> <ZoneTemplate> <asp:Table runat="server" ID="table2" Title="Employee Extensions"> <asp:TableHeaderRow> <asp:TableHeaderCell>Employee Name</asp:TableHeaderCell> <asp:TableHeaderCell>Extension</asp:TableHeaderCell> </asp:TableHeaderRow> <asp:TableRow> <asp:TableCell>Alberts, Amy</asp:TableCell> <asp:TableCell>x9764</asp:TableCell> </asp:TableRow> <asp:TableRow> <asp:TableCell>Hanif, Karim</asp:TableCell> <asp:TableCell>x3240</asp:TableCell> </asp:TableRow> <asp:TableRow> <asp:TableCell>Penor, Lori</asp:TableCell> <asp:TableCell>x4165</asp:TableCell> </asp:TableRow> </asp:Table> </ZoneTemplate> </asp:WebPartZone> </asp:TableCell> </asp:TableRow> </asp:Table> </div> <hr /> <asp:Table ID="Table3" runat="server"> <asp:TableRow> <asp:TableCell> <asp:Button ID="Button1" runat="server" Width ="200" Text="Total Zone Count" OnClick="Button1_Click" /> <br /> <asp:Button ID="Button2" runat="server" Width ="200" Text="Coll. Contains WebPartZone2" OnClick="Button2_Click" /> <br /> <asp:Button ID="Button3" runat="server" Width ="200" Text="Zone Names from Array" OnClick="Button3_Click" /> <br /> <asp:Button ID="Button4" runat="server" Width ="200" Text="WebPartZone1 Index" OnClick="Button4_Click" /> <br /> <asp:Button ID="Button5" runat="server" Width ="200" Text="Toggle Verb Render Mode" OnClick="Button5_Click" /> </asp:TableCell> <asp:TableCell HorizontalAlign="right" Width="200" VerticalAlign="top"> <asp:Label ID="Label1" runat="server" Font-Bold="true" /> </asp:TableCell> </asp:TableRow> </asp:Table> </form> </body> </html>
<%@ Page Language="C#" Codefile="webpartzonecollection_overview.cs" Inherits="webpartzonecollection_overview" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html > <head runat="server"> <title>WebPartZoneCollection Demo</title> </head> <body> <form id="form1" runat="server"> <div> <asp:WebPartManager ID="mgr" runat="server" /> <asp:Table runat="server"> <asp:TableRow> <asp:TableCell> <asp:Label ID="lblZone1" runat="server" Font-Bold="true"> WebPartZone1 Contents </asp:Label> <asp:WebPartZone ID="WebPartZone1" runat="server" Width="230"> <ZoneTemplate> <asp:BulletedList ID="BulletedList1" Runat="server" DisplayMode="HyperLink" Title="Favorite Links" CatalogIconImageUrl="Mine.gif"> <asp:ListItem Value="http://msdn.microsoft.com"> MSDN </asp:ListItem> <asp:ListItem Value="http://www.asp.net"> ASP.NET </asp:ListItem> <asp:ListItem Value="http://www.msn.com"> MSN </asp:ListItem> </asp:BulletedList> </ZoneTemplate> </asp:WebPartZone> <div> <asp:Label ID="lblZone2" runat="server" Font-Bold="true"> WebPartZone2 Contents </asp:Label> </div> <asp:WebPartZone ID="WebPartZone2" runat="server" Width="230"> <ZoneTemplate> <asp:Calendar ID="Calendar1" runat="server" Title="My Calendar" /> </ZoneTemplate> </asp:WebPartZone> </asp:TableCell> <asp:TableCell VerticalAlign="top"> <asp:Label ID="lblZone3" runat="server" Font-Bold="true"> WebPartZone3 Contents </asp:Label> <asp:WebPartZone ID="WebPartZone3" runat="server"> <ZoneTemplate> <asp:Table runat="server" ID="table1" Title="Employee Extensions"> <asp:TableHeaderRow> <asp:TableHeaderCell>Employee Name</asp:TableHeaderCell> <asp:TableHeaderCell>Extension</asp:TableHeaderCell> </asp:TableHeaderRow> <asp:TableRow> <asp:TableCell>Alberts, Amy</asp:TableCell> <asp:TableCell>x9764</asp:TableCell> </asp:TableRow> <asp:TableRow> <asp:TableCell>Hanif, Karim</asp:TableCell> <asp:TableCell>x3240</asp:TableCell> </asp:TableRow> <asp:TableRow> <asp:TableCell>Penor, Lori</asp:TableCell> <asp:TableCell>x4165</asp:TableCell> </asp:TableRow> </asp:Table> </ZoneTemplate> </asp:WebPartZone> </asp:TableCell> </asp:TableRow> </asp:Table> </div> <hr /> <asp:Table runat="server"> <asp:TableRow> <asp:TableCell> <asp:Button ID="Button1" runat="server" Width ="200" Text="Total Zone Count" OnClick="Button1_Click" /> <br /> <asp:Button ID="Button2" runat="server" Width ="200" Text="Coll. Contains WebPartZone2" OnClick="Button2_Click" /> <br /> <asp:Button ID="Button3" runat="server" Width ="200" Text="Zone Names from Array" OnClick="Button3_Click" /> <br /> <asp:Button ID="Button4" runat="server" Width ="200" Text="WebPartZone1 Index" OnClick="Button4_Click" /> <br /> <asp:Button ID="Button5" runat="server" Width ="200" Text="Toggle Verb Render Mode" OnClick="Button5_Click" /> </asp:TableCell> <asp:TableCell HorizontalAlign="right" Width="200" VerticalAlign="top"> <asp:Label ID="Label1" runat="server" Font-Bold="true" /> </asp:TableCell> </asp:TableRow> </asp:Table> </form> </body> </html>
コード例の 2 番目の部分は、WebPartZoneCollection クラスの使用を示すコードを含む部分クラスです。このコードは、Web ページのイベントを処理します。
Imports System Imports System.Data Imports System.Configuration Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Web.UI.HtmlControls Partial Public Class webpartzonecollection_overview Inherits Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Label1.Text = String.Empty Label1.Text = "WebPartZone Count: " & mgr.Zones.Count End Sub Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Label1.Text = String.Empty Label1.Text = mgr.Zones.Contains(WebPartZone2).ToString() End Sub Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Label1.Text = String.Empty Dim zoneArray(mgr.Zones.Count) As WebPartZoneBase mgr.Zones.CopyTo(zoneArray, 0) Label1.Text = zoneArray(2).ID Label1.Text += ", " & zoneArray(1).ID Label1.Text += ", " & zoneArray(0).ID End Sub Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Label1.Text = String.Empty Label1.Text = "WebPartZone1 index: " & mgr.Zones.IndexOf(WebPartZone1) End Sub 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 End Class
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class webpartzonecollection_overview : System.Web.UI.Page { protected void Button1_Click(object sender, EventArgs e) { Label1.Text = String.Empty; Label1.Text = "WebPartZone Count: " + mgr.Zones.Count; } protected void Button2_Click(object sender, EventArgs e) { Label1.Text = String.Empty; Label1.Text = mgr.Zones.Contains(WebPartZone2).ToString(); } protected void Button3_Click(object sender, EventArgs e) { Label1.Text = String.Empty; WebPartZoneBase[] zoneArray = new WebPartZoneBase[mgr.Zones.Count]; mgr.Zones.CopyTo(zoneArray, 0); Label1.Text = zoneArray[2].ID; Label1.Text += ", " + zoneArray[1].ID; Label1.Text += ", " + zoneArray[0].ID; } protected void Button4_Click(object sender, EventArgs e) { Label1.Text = String.Empty; Label1.Text = "WebPartZone1 index: " + mgr.Zones.IndexOf(WebPartZone1); } 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; } } }
ブラウザでページを読み込みます。3 つの WebPartZone ゾーンが、格納しているサーバー コントロールと共に表示されます。ページの下部には、複数のボタンがあり、それぞれが WebPartZoneCollection オブジェクトを使用する動作をデモンストレーションします。各ボタンをクリックして、ゾーンとその内容に対する効果を確認します。WebPartZoneCollection オブジェクトのいくつかの側面を示す各ボタンに関連付けられたコードを表示するには、上記のこのコード例の 2 番目の部分として参照される部分クラス ファイルのコードを表示します。


System.Collections.ReadOnlyCollectionBase
System.Web.UI.WebControls.WebParts.WebPartZoneCollection


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


WebPartZoneCollection コンストラクタ ()
アセンブリ: System.Web (system.web.dll 内)


WebPartManager コントロールは、このコンストラクタを、それ自体のコンストラクタ内で使用して、Web パーツ ページの WebPartZoneCollection クラスの新しいインスタンスを初期化します。

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


WebPartZoneCollection クラス
WebPartZoneCollection メンバ
System.Web.UI.WebControls.WebParts 名前空間
その他の技術情報
ASP.NET Web パーツ ページ
ASP.NET Web パーツ ページ
WebPartZoneCollection コンストラクタ (ICollection)
アセンブリ: System.Web (system.web.dll 内)

- webPartZones
WebPartZone オブジェクトの ICollection。


WebPartZone オブジェクトのカスタム コレクションを作成し、それに対してプログラムによって操作を実行する場合に、WebPartZoneCollection コンストラクタを使用します。たとえば、Zones プロパティにアクセスし、Web パーツ ページの WebPartZone オブジェクトのサブセットを WebPartZoneCollection オブジェクトに割り当てて作成し、ゾーンのそのサブセットだけの子コントロールまたは各種プロパティに対して操作を実行できます。

WebPartZoneCollection コンストラクタの使用方法を次のコード例に示します。この例の完全なコードは、WebPartZoneCollection の概要にある「例」のセクションを参照してください。
コードの次のセクションでは、Zones プロパティの値を取得することによって、WebPartZoneCollection オブジェクトを変数に割り当てています。必要な場合は、Zones プロパティからすべてのゾーンを割り当てるのではなく、ページのすべてのゾーンのサブセットを格納する WebPartZoneBase オブジェクトの配列を作成し、その配列を新しい WebPartZoneCollection オブジェクトに割り当てることができます。
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
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; } }
コレクションを作成した後は、コレクションを反復処理して、格納されているすべてのゾーンまたはその内容に対して操作を実行できます。プログラム例を実行するには、ブラウザにページを読み込み、各ゾーンの [Toggle Verb Render Mode] ボタンをクリックします。これによって、ゾーン内の各サーバー コントロールのタイトル バーの動詞の表示方法が変更されます。動詞は、ドロップダウン メニューに、またはタイトル バーに直接リンクとして表示できます。

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


WebPartZoneCollection コンストラクタ
WebPartZoneCollection コンストラクタは、WebPartManager コントロール、Web パーツ コントロール セット内の他のコントロール、またはカスタムの開発者のコードによって、Web パーツ ページ上に存在する WebPartZone コントロールの読み取り専用のコレクションを作成するために使用されます。
ASP.NET Web パーツ ページ
名前 | 説明 |
---|---|
WebPartZoneCollection () | WebPartZoneCollection クラスの空のインスタンスを初期化します。 |
WebPartZoneCollection (ICollection) | WebPartZoneCollection クラスのインスタンスを、WebPartZone オブジェクトのコレクションを渡すことによって初期化します。 |

関連項目
WebPartZoneCollection クラスWebPartZoneCollection メンバ
System.Web.UI.WebControls.WebParts 名前空間
その他の技術情報
ASP.NET Web パーツ ページASP.NET Web パーツ ページ
WebPartZoneCollection プロパティ

名前 | 説明 | |
---|---|---|
![]() | Count | ReadOnlyCollectionBase インスタンスに格納されている要素の数を取得します。 ( ReadOnlyCollectionBase から継承されます。) |
![]() | Item | オーバーロードされます。 コレクションにおける位置と一意の識別子に基づいて特定のメンバを返します。 |

名前 | 説明 | |
---|---|---|
![]() | InnerList | ReadOnlyCollectionBase インスタンスに格納されている要素のリストを取得します。 ( ReadOnlyCollectionBase から継承されます。) |

関連項目
WebPartZoneCollection クラスSystem.Web.UI.WebControls.WebParts 名前空間
WebPartManager.Zones プロパティ
その他の技術情報
ASP.NET Web パーツ ページWebPartZoneCollection メソッド

名前 | 説明 | |
---|---|---|
![]() | Contains | 特定のゾーンがコレクション内に存在するかどうかを示す値を返します。 |
![]() | CopyTo | コレクションを WebPartZoneBase オブジェクトの配列にコピーします。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetEnumerator | ReadOnlyCollectionBase インスタンスを反復処理する列挙子を返します。 ( ReadOnlyCollectionBase から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | IndexOf | コレクション内の特定のメンバの位置を返します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

関連項目
WebPartZoneCollection クラスSystem.Web.UI.WebControls.WebParts 名前空間
WebPartManager.Zones プロパティ
その他の技術情報
ASP.NET Web パーツ ページWebPartZoneCollection メンバ
WebPartZone コントロールの読み取り専用のコレクションを含みます。
WebPartZoneCollection データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Count | ReadOnlyCollectionBase インスタンスに格納されている要素の数を取得します。(ReadOnlyCollectionBase から継承されます。) |
![]() | Item | オーバーロードされます。 コレクションにおける位置と一意の識別子に基づいて特定のメンバを返します。 |

名前 | 説明 | |
---|---|---|
![]() | InnerList | ReadOnlyCollectionBase インスタンスに格納されている要素のリストを取得します。(ReadOnlyCollectionBase から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Contains | 特定のゾーンがコレクション内に存在するかどうかを示す値を返します。 |
![]() | CopyTo | コレクションを WebPartZoneBase オブジェクトの配列にコピーします。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetEnumerator | ReadOnlyCollectionBase インスタンスを反復処理する列挙子を返します。 (ReadOnlyCollectionBase から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | IndexOf | コレクション内の特定のメンバの位置を返します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

関連項目
WebPartZoneCollection クラスSystem.Web.UI.WebControls.WebParts 名前空間
WebPartManager.Zones プロパティ
その他の技術情報
ASP.NET Web パーツ ページWeblioに収録されているすべての辞書からWebPartZoneCollectionを検索する場合は、下記のリンクをクリックしてください。

- WebPartZoneCollectionのページへのリンク