CatalogPartCollection クラス

定義

エンド ユーザーが Web ページに追加できる Web サーバー コントロールのカタログを提供する CatalogPart コントロールのコレクションを格納します。 このクラスは継承できません。

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

次のコード例では、 クラスのいくつかの使用方法を CatalogPartCollection 示します。 このコード例には、次の 4 つの部分があります。

  • Web パーツ ページの表示モードを変更できるユーザー コントロール。

  • という名前TextDisplayWebPartのカスタム WebPart コントロールのクラス。これは Web ページで参照され、コントロールの CatalogPart 1 つに含まれています。

  • コントロールを TextDisplayWebPart 参照する Web ページには CatalogZone 、ゾーンで宣言されている Web パーツ コントロール セットの CatalogPart 2 つのコントロールを含むコントロールが含まれており、オブジェクトを作成および操作するためのイベント ドリブン コードが CatalogPartCollection 含まれています。

  • ブラウザーでコード例を読み込む場合の動作の説明。

コード例の最初の部分は、ユーザー コントロールです。 ユーザー コントロールのソース コードは、別のトピックから取得されます。 このコード例を機能させるには、「 チュートリアル: Web パーツ ページでの表示モードの変更 」トピックからユーザー コントロールの .ascx ファイルを取得し、このコード例の .aspx ページと同じフォルダーにファイルを配置する必要があります。

コード例の 2 番目の部分は コントロール TextDisplayWebPart です。 コード例を実行するには、このソース コードをコンパイルする必要があります。 これを明示的にコンパイルし、結果のアセンブリを Web サイトの Bin フォルダーまたはグローバル アセンブリ キャッシュに配置できます。 または、ソース コードをサイトの App_Code フォルダーに配置して、実行時に動的にコンパイルすることもできます。 両方のコンパイル方法を示すチュートリアルについては、「 チュートリアル: カスタム Web サーバー コントロールの開発と使用」を参照してください。 コントロールには という名前 ContentTextのプロパティがあることに注意してください。このプロパティは、ユーザーがテキスト ボックスに入力した値を保持します。

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  public class TextDisplayWebPart : WebPart
  {
    private String _contentText = null;
    TextBox input;
    Label DisplayContent;
    Literal lineBreak;

    [Personalizable(), WebBrowsable]
    public String ContentText
    {
      get { return _contentText; }
      set { _contentText = value; }
    }

    protected override void CreateChildControls()
    {
      Controls.Clear();
      DisplayContent = new Label();
      DisplayContent.BackColor = Color.LightBlue;
      DisplayContent.Text = this.ContentText;
      this.Controls.Add(DisplayContent);

      lineBreak = new Literal();
      lineBreak.Text = @"<br />";
      Controls.Add(lineBreak);

      input = new TextBox();
      this.Controls.Add(input);
      Button update = new Button();
      update.Text = "Set Label Content";
      update.Click += new EventHandler(this.submit_Click);
      this.Controls.Add(update);
    }

    private void submit_Click(object sender, EventArgs e)
    {
      // Update the label string.
      if (!string.IsNullOrEmpty(input.Text))
      {
        _contentText = input.Text + @"<br />";
        input.Text = String.Empty;
        DisplayContent.Text = this.ContentText;
      }
    }
  }
}
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
Imports System.Security.Permissions
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts

Namespace Samples.AspNet.VB.Controls

  <AspNetHostingPermission(SecurityAction.Demand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  Public Class TextDisplayWebPart
    Inherits WebPart
    Private _contentText As String = Nothing
    Private _fontStyle As String = Nothing
    Private input As TextBox
    Private DisplayContent As Label
    Private lineBreak As Literal

    <Personalizable(), WebBrowsable()> _
    Public Property ContentText() As String
      Get
        Return _contentText
      End Get
      Set(ByVal value As String)
        _contentText = value
      End Set
    End Property

    Protected Overrides Sub CreateChildControls()
      Controls.Clear()
      DisplayContent = New Label()
      DisplayContent.BackColor = Color.LightBlue
      DisplayContent.Text = Me.ContentText
      Me.Controls.Add(DisplayContent)

      lineBreak = New Literal()
      lineBreak.Text = "<br />"
      Controls.Add(lineBreak)

      input = New TextBox()
      Me.Controls.Add(input)
      Dim update As New Button()
      update.Text = "Set Label Content"
      AddHandler update.Click, AddressOf Me.submit_Click
      Me.Controls.Add(update)

    End Sub

    Private Sub submit_Click(ByVal sender As Object, _
                             ByVal e As EventArgs)
      ' Update the label string.
      If input.Text <> String.Empty Then
        _contentText = input.Text + "<br />"
        input.Text = String.Empty
        DisplayContent.Text = Me.ContentText
      End If

    End Sub

  End Class

End Namespace

コード例の 3 番目の部分は Web ページです。 ページの 要素に <asp:catalogzone> 2 つの CatalogPart コントロールの宣言が含まれていることに注意してください。 これらのコントロールは、メソッドの実行時に作成されるカスタム CatalogPartCollection オブジェクトの Button1_Click 一部になります。 PageCatalogPartコントロールには、実行時にユーザーによって以前に閉じられていた Web サーバー コントロールが含まれています。 コントロール内のコントロールは PageCatalogPart 、ページに再度追加できます。 コントロールには DeclarativeCatalogPart 、カスタム TextDisplayWebPart コントロールの宣言が含まれています。 ページがカタログ モードの場合、ユーザーはコントロールを TextDisplayWebPart ページに追加して、通常のブラウズ モードで使用できるようにします。

<%@ Page Language="C#" %>
<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenuCS" 
  Src="DisplayModeMenuCS.ascx" %>
<%@ Register TagPrefix="aspSample"
  Namespace="Samples.AspNet.CS.Controls" 
  Assembly="TextDisplayWebPartCS" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  // <snippet2>
  protected void Button1_Click(object sender, EventArgs e)
  {
    ArrayList list = new ArrayList(2);
    list.Add(PageCatalogPart1);
    list.Add(DeclarativeCatalogPart1);
    // Pass an ICollection object to the constructor.
    CatalogPartCollection myParts = new CatalogPartCollection(list);
    foreach (CatalogPart catalog in myParts)
    {
      catalog.Description = "My " + catalog.DisplayTitle;
    }

    // Use the IndexOf property to locate a CatalogPart control.
    int PageCatalogPartIndex = myParts.IndexOf(PageCatalogPart1);
    myParts[PageCatalogPartIndex].ChromeType = PartChromeType.TitleOnly;

    // Use the Contains method to see if a CatalogPart control exists.
    if (myParts.Contains(PageCatalogPart1))
    {
      WebPart closedWebPart = null;
      WebPartDescriptionCollection descriptions = PageCatalogPart1.GetAvailableWebPartDescriptions();
      if (descriptions.Count > 0)
      {
        closedWebPart = PageCatalogPart1.GetWebPart(descriptions[0]);
        closedWebPart.AllowClose = false;
      }
    }
    
    // Use indexers to display the details of the CatalogPart controls.
    Label1.Text = String.Empty;
    Label1.Text =
      "<h3>PageCatalogPart Details</h3>" +
      "ID: " + myParts[0].ID + "<br />" +
      "Count: " + myParts[0].GetAvailableWebPartDescriptions().Count;
    Label1.Text += 
      "<h3>DeclarativeCatalogPart Details</h3>" +
      "ID: " + myParts["DeclarativeCatalogPart1"].ID + "<br />" +
      "Count: " + myParts["DeclarativeCatalogPart1"].GetAvailableWebPartDescriptions().Count;
  }
  // </snippet2>
</script> 
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>PageCatalogPart Details</title>
</head>
<body>
  <form id="form1" runat="server">
    <asp:WebPartManager ID="WebPartManager1" runat="server" />
    <uc1:DisplayModeMenuCS ID="DisplayModeMenu1" runat="server" />
    <asp:WebPartZone ID="WebPartZone1" runat="server">
      <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>
    <asp:CatalogZone ID="CatalogZone1" runat="server">
      <ZoneTemplate>
        <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" runat="server">
          <WebPartsTemplate>
            <aspSample:TextDisplayWebPart runat="server" 
              id="TextDisplayWebPart1"
              Title="Text Display WebPart" />
          </WebPartsTemplate>
        </asp:DeclarativeCatalogPart>
        <asp:PageCatalogPart ID="PageCatalogPart1" runat="server" />  
      </ZoneTemplate>
    </asp:CatalogZone>
    <hr />
    <asp:Button ID="Button1" 
      runat="server" 
      Text="Display CatalogPart Properties" 
      OnClick="Button1_Click"/>
    <br />
    <asp:Label ID="Label1" runat="server" Text="" /> 
  </form>
</body>
</html>
<%@ Page Language="vb" %>
<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenuVB" 
  Src="DisplayModeMenuVB.ascx" %>
<%@ Register TagPrefix="aspSample"
  Namespace="Samples.AspNet.VB.Controls" 
  Assembly="TextDisplayWebPartVB" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
' <snippet2>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) 
    Dim list As New ArrayList(2)
    list.Add(PageCatalogPart1)
    list.Add(DeclarativeCatalogPart1)
    ' Pass an ICollection object to the constructor.
    Dim myParts As New CatalogPartCollection(list)
    Dim catalog As CatalogPart
    For Each catalog In  myParts
        catalog.Description = "My " + catalog.DisplayTitle
    Next catalog
    
    ' Use the IndexOf property to locate a CatalogPart control.
    Dim PageCatalogPartIndex As Integer = _
      myParts.IndexOf(PageCatalogPart1)
    myParts(PageCatalogPartIndex).ChromeType = PartChromeType.TitleOnly
    
    ' Use the Contains method to see if a CatalogPart control exists.
    If myParts.Contains(PageCatalogPart1) Then
        Dim closedWebPart As WebPart = Nothing
        Dim descriptions As WebPartDescriptionCollection = _
          PageCatalogPart1.GetAvailableWebPartDescriptions()
        If descriptions.Count > 0 Then
            closedWebPart = PageCatalogPart1.GetWebPart(descriptions(0))
            closedWebPart.AllowClose = False
        End If
    End If
    
    ' Use indexers to display the details of the CatalogPart controls.
    Label1.Text = String.Empty
    Label1.Text = _
      "<h3>PageCatalogPart Details</h3>" & _
      "ID: " & myParts(0).ID + "<br />" & _
      "Count: " & myParts(0).GetAvailableWebPartDescriptions().Count
    Label1.Text += _
      "<h3>DeclarativeCatalogPart Details</h3>" & _
      "ID: " & myParts("DeclarativeCatalogPart1").ID & "<br />" & _
      "Count: " & myParts("DeclarativeCatalogPart1") _
        .GetAvailableWebPartDescriptions().Count

End Sub 
' </snippet2>
</script>  
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>PageCatalogPart Details</title>
</head>
<body>
  <form id="form1" runat="server">
    <asp:WebPartManager ID="WebPartManager1" runat="server" />
    <uc1:DisplayModeMenuVB ID="DisplayModeMenu1" runat="server" />
    <asp:WebPartZone ID="WebPartZone1" runat="server">
      <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>
    <asp:CatalogZone ID="CatalogZone1" runat="server">
      <ZoneTemplate>
        <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" runat="server">
          <WebPartsTemplate>
            <aspSample:TextDisplayWebPart runat="server" 
              id="TextDisplayWebPart1"
              Title="Text Display WebPart" />
          </WebPartsTemplate>
        </asp:DeclarativeCatalogPart>
        <asp:PageCatalogPart ID="PageCatalogPart1" runat="server" />  
      </ZoneTemplate>
    </asp:CatalogZone>
    <hr />
    <asp:Button ID="Button1" 
      runat="server" 
      Text="Display CatalogPart Properties" 
      OnClick="Button1_Click"/>
    <br />
    <asp:Label ID="Label1" runat="server" Text="" /> 
  </form>
</body>
</html>

ブラウザーでページを読み込むときは、[表示モード] ドロップダウン リスト コントロールで [カタログ] を選択して、ページを カタログモード に切り替えることができます。 ページの横にあるチェック ボックスをオンにして [追加] をクリックすると、カスタム WebPart コントロールをページに 追加できます。 [ 閉じる ] をクリックして、ページを参照モードに戻します。 追加したコントロールで、動詞メニュー (タイトル バーに表示される下矢印) をクリックし、[ 閉じる] をクリックすると、コントロールがページから削除され、コントロールに PageCatalogPart 追加されます。 ページをカタログ モードに戻し、[ ページ カタログ ] リンクをクリックしてコントロールの内容を PageCatalogPart 表示します。 閉じたコントロールがそこに表示されます。 [ CatalogPart プロパティの表示 ] ボタンをクリックすると、オブジェクトに CatalogPartCollection アクセスし、含まれている CatalogPart コントロールの特定のプロパティが表示されます。

注釈

クラスは CatalogPartCollection 、コントロールの読み取り専用コレクション CatalogPart であり、通常はゾーンに CatalogZoneBase 含まれるコントロールの CatalogPart セットを追跡するためにゾーンによって使用されます。

Web パーツ ページがカタログ モードになると、コントロールで構成される新しい CatalogPartCollection オブジェクトがゾーンによって CatalogPart 作成されます。 コレクション内の各 CatalogPart コントロールには、使用可能なサーバー コントロールのカタログ形式で表示される 0 個以上の Web サーバー コントロールへの参照を含めることができます。

たとえば、一連のコントロールに対して一括操作を実行する必要がある場合は、独自のプログラムで使用するコントロールのCatalogPartコレクションを作成CatalogPartCollectionできます。 オブジェクトは CatalogPartCollection 読み取り専用ですが、コレクションで参照されている基になるコントロールにプログラムで変更を加えることができます。

コンストラクター

CatalogPartCollection()

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

CatalogPartCollection(CatalogPartCollection, ICollection)

ゾーン内の既存の CatalogPartCollection コントロールの ICollection コレクションおよび追加のコントロールのコレクションで渡すことによって、CatalogPart クラスの新しいインスタンスを初期化します。

CatalogPartCollection(ICollection)

CatalogPartCollection コントロールの ICollection コレクションを渡すことによって、CatalogPart クラスの新しいインスタンスを初期化します。

フィールド

Empty

コレクションの静的で読み取り専用である空のインスタンスを参照します。

プロパティ

Count

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

(継承元 ReadOnlyCollectionBase)
InnerList

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

(継承元 ReadOnlyCollectionBase)
Item[Int32]

コレクション内の位置に基づいて、コレクションのメンバーを取得または設定します。

Item[String]

一意の文字列識別子に基づいて、コレクションのメンバーを返します。

メソッド

Contains(CatalogPart)

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

CopyTo(CatalogPart[], Int32)

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

Equals(Object)

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

(継承元 Object)
GetEnumerator()

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

(継承元 ReadOnlyCollectionBase)
GetHashCode()

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

(継承元 Object)
GetType()

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

(継承元 Object)
IndexOf(CatalogPart)

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

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 に変換します。

適用対象

こちらもご覧ください