WebPartZoneCollection クラス

定義

WebPartZone コントロールの読み取り専用コレクションを格納します。

public ref class WebPartZoneCollection sealed : System::Collections::ReadOnlyCollectionBase
public sealed class WebPartZoneCollection : System.Collections.ReadOnlyCollectionBase
type WebPartZoneCollection = class
    inherit ReadOnlyCollectionBase
Public NotInheritable Class WebPartZoneCollection
Inherits ReadOnlyCollectionBase
継承
WebPartZoneCollection

次のコード例では、 クラスの使用方法を WebPartZoneCollection 示します。 このコード例には、コードの 2 つのセクションと、この例を実行する方法の説明という 3 つの部分が含まれています。

コード例の最初の部分は、3 つの WebPartZone コントロールを含む Web ページであり、それぞれに 1 つのサーバー コントロールが含まれています。 これらのサーバー コントロールはすべて標準の ASP.NET コントロールですが、ゾーン内WebPartZoneに配置されるため、実行時にコントロールとしてWebPart機能できます。

<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
<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"
            AssociatedControlID="WebPartZone1">
            WebPartZone1 Contents
          </asp:Label>
          <asp:WebPartZone ID="WebPartZone1" 
            runat="server" Width="230">
            <ZoneTemplate>
              <asp:BulletedList 
                ID="BulletedList1" 
                Runat="server"
                DisplayMode="HyperLink"
                Title="Favorite Links">
                <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"
            AssociatedControlID="WebPartZone2">
            WebPartZone2 Contents
          </asp:Label>
          </div>
          <asp:WebPartZone ID="WebPartZone2" 
            runat="server" Width="230">
            <ZoneTemplate>
              <asp:Calendar ID="Calendar1" 
                runat="server" 
                Title="My Calendar" 
                CatalogIconImageUrl="Mine.gif" />
            </ZoneTemplate>
          </asp:WebPartZone> 
        </asp:TableCell>
        <asp:TableCell VerticalAlign="top"> 
          <asp:Label ID="lblZone3" runat="server" 
            Font-Bold="true" 
            AssociatedControlID="WebPartZone3">
            WebPartZone3 Contents
          </asp:Label>
          <asp:WebPartZone ID="WebPartZone3" runat="server">
            <ZoneTemplate>
              <asp:Table runat="server" ID="table2" 
                Title="Employee Extensions">
                <asp:TableHeaderRow>
                  <asp:TableHeaderCell Scope="Column">
                    Employee Name</asp:TableHeaderCell>
                  <asp:TableHeaderCell Scope="Column">
                    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" OnClick="Button1_Click" 
            Text="Total Zone Count" />
          <br />
          <asp:Button ID="Button2" runat="server" 
            Width ="200" OnClick="Button2_Click"
            Text="Coll. Contains WebPartZone2" />
          <br />
          <asp:Button ID="Button3" runat="server" 
            Width ="200" OnClick="Button3_Click"
            Text="Zone Names from Array" />
          <br />
          <asp:Button ID="Button4" runat="server" 
            Width ="200" OnClick="Button4_Click"
            Text="WebPartZone1 Index" />  
          <br />
          <asp:Button ID="Button5" runat="server" 
            Width ="200" OnClick="Button5_Click"
            Text="Toggle Verb Render Mode" />
        </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="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 xmlns="http://www.w3.org/1999/xhtml" >
<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"
            AssociatedControlID="WebPartZone1">
            WebPartZone1 Contents
          </asp:Label>
          <asp:WebPartZone ID="WebPartZone1" 
            runat="server" Width="230">
            <ZoneTemplate>
              <asp:BulletedList 
                ID="BulletedList1" 
                Runat="server"
                DisplayMode="HyperLink"
                Title="Favorite Links">
                <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"
            AssociatedControlID="WebPartZone2">
            WebPartZone2 Contents
          </asp:Label>
          </div>
          <asp:WebPartZone ID="WebPartZone2" 
            runat="server" Width="230">
            <ZoneTemplate>
              <asp:Calendar ID="Calendar1" 
                runat="server" 
                Title="My Calendar" 
                CatalogIconImageUrl="Mine.gif" />
            </ZoneTemplate>
          </asp:WebPartZone> 
        </asp:TableCell>
        <asp:TableCell VerticalAlign="top"> 
          <asp:Label ID="lblZone3" runat="server" 
            Font-Bold="true" 
            AssociatedControlID="WebPartZone3">
            WebPartZone3 Contents
          </asp:Label>
          <asp:WebPartZone ID="WebPartZone3" runat="server">
            <ZoneTemplate>
              <asp:Table runat="server" ID="table2" 
                Title="Employee Extensions">
                <asp:TableHeaderRow>
                  <asp:TableHeaderCell Scope="Column">
                    Employee Name</asp:TableHeaderCell>
                  <asp:TableHeaderCell Scope="Column">
                    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" OnClick="Button1_Click" 
            Text="Total Zone Count" />
          <br />
          <asp:Button ID="Button2" runat="server" 
            Width ="200" OnClick="Button2_Click"
            Text="Coll. Contains WebPartZone2" />
          <br />
          <asp:Button ID="Button3" runat="server" 
            Width ="200" OnClick="Button3_Click"
            Text="Zone Names from Array" />
          <br />
          <asp:Button ID="Button4" runat="server" 
            Width ="200" OnClick="Button4_Click"
            Text="WebPartZone1 Index" />  
          <br />
          <asp:Button ID="Button5" runat="server" 
            Width ="200" OnClick="Button5_Click"
            Text="Toggle Verb Render Mode" />
        </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 ページのイベントを処理します。

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;
    }
  }
}
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

ブラウザーにページを読み込みます。 3 つの WebPartZone ゾーンは、包含サーバー コントロールで表示されます。 ページの下部には複数のボタンがあり、それぞれにオブジェクトの操作の一部の側面が WebPartZoneCollection 示されています。 各ボタンをクリックすると、ゾーンとその内容に対する効果が表示されます。 オブジェクトの一部を示す各ボタンに関連付けられているコードを WebPartZoneCollection 表示するには、このコード例の 2 番目の部分として上記で参照されている部分クラス ファイルのコードを表示します。

注釈

クラスには 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()

WebPartZoneCollection クラスの空のインスタンスを初期化します。

WebPartZoneCollection(ICollection)

WebPartZoneCollection クラスのインスタンスを、WebPartZone オブジェクトのコレクションを渡すことによって初期化します。

プロパティ

Count

ReadOnlyCollectionBase インスタンスに含まれる要素の数を取得します。

(継承元 ReadOnlyCollectionBase)
InnerList

ReadOnlyCollectionBase インスタンスに格納されている要素のリストを取得します。

(継承元 ReadOnlyCollectionBase)
Item[Int32]

整数を渡すことによって、コレクションの特定のメンバーを返します。

Item[String]

一意の識別子を渡すことによって、コレクションの特定のメンバーを返します。

メソッド

Contains(WebPartZoneBase)

特定のゾーンがコレクション内に存在するかどうかを示す値を返します。

CopyTo(WebPartZoneBase[], Int32)

コレクションを WebPartZoneBase オブジェクトの配列にコピーします。

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetEnumerator()

ReadOnlyCollectionBase インスタンスを反復処理する列挙子を返します。

(継承元 ReadOnlyCollectionBase)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IndexOf(WebPartZoneBase)

コレクション内の特定のメンバーの位置を返します。

MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

明示的なインターフェイスの実装

ICollection.CopyTo(Array, Int32)

ReadOnlyCollectionBase 全体を互換性のある 1 次元の Array にコピーします。コピー操作は、コピー先の配列の指定したインデックスから始まります。

(継承元 ReadOnlyCollectionBase)
ICollection.IsSynchronized

ReadOnlyCollectionBase オブジェクトへのアクセスが同期されている (スレッド セーフである) かどうかを示す値を取得します。

(継承元 ReadOnlyCollectionBase)
ICollection.SyncRoot

ReadOnlyCollectionBase オブジェクトへのアクセスを同期するために使用できるオブジェクトを取得します。

(継承元 ReadOnlyCollectionBase)

拡張メソッド

Cast<TResult>(IEnumerable)

IEnumerable の要素を、指定した型にキャストします。

OfType<TResult>(IEnumerable)

指定された型に基づいて IEnumerable の要素をフィルター処理します。

AsParallel(IEnumerable)

クエリの並列化を有効にします。

AsQueryable(IEnumerable)

IEnumerableIQueryable に変換します。

適用対象

こちらもご覧ください