CatalogPartCollection クラス
アセンブリ: System.Web (system.web.dll 内)
構文
CatalogPartCollection クラスは、CatalogPart コントロールの読み取り専用のコレクションで、通常、ゾーンによって格納される CatalogPart コントロールのセットを追跡するために、CatalogZoneBase ゾーンによって使用されます。
Web パーツ ページがカタログ モードになっている場合、ゾーンは CatalogPart コントロールで構成される新しい CatalogPartCollection オブジェクトを作成します。コレクションの各 CatalogPart コントロールには、使用できるサーバー コントロールのカタログの形式で表示される 0 個以上の Web サーバー コントロールへの参照を格納できます。
たとえば、CatalogPart コントロールのセットに対し多量の操作を一度に実行する必要がある場合、独自にプログラムから実行できるよう、コントロールの CatalogPartCollection コレクションを作成できます。CatalogPartCollection オブジェクトは読み取り専用ですが、このコレクションで参照される基になるコントロールをプログラムから変更できます。
CatalogPartCollection クラスを使用するいくつかの方法を次のコード例に示します。このコード例は、4 つの部分から構成されます。
-
TextDisplayWebPart という名前のカスタム WebPart コントロールのクラス。このクラスは、Web ページで参照され、CatalogPart コントロールの 1 つに含まれます。
-
TextDisplayWebPart コントロールを参照し、CatalogZone コントロールと共に、ゾーン内で宣言された Web パーツ コントロール セットの 2 つの CatalogPart コントロールを含み、さらに CatalogPartCollection オブジェクトの作成と操作のためのイベント ドリブン コードを含んだ Web ページ。
コード例の最初の部分は、ユーザー コントロールです。ユーザー コントロールのソース コードは、別のトピックのものを使用しています。このコード例を実行するには、チュートリアル : Web パーツ ページでの表示モードの変更 のトピックに記載されているユーザー コントロールの .ascx ファイルを、このコード例に示されている .ascx ページと同じフォルダに配置する必要があります。
コード例の 2 番目の部分は TextDisplayWebPart コントロールです。コード例を実行するためには、このソース コードをコンパイルする必要があります。それを明示的にコンパイルし、コンパイル済みのアセンブリを Web サイトの Bin フォルダまたはグローバル アセンブリ キャッシュに配置できます。サイトの App_Code フォルダにソース コードを配置し、実行時に動的にコンパイルすることもできます。両方のコンパイル方法を示すチュートリアルについては、「チュートリアル : カスタム サーバー コントロールの開発と使用」を参照してください。このコントロールは、ContentText という名前のプロパティを持っています。このプロパティは、ユーザーがテキスト ボックスに入力した値を保持します。
Imports System 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
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 (input.Text != String.Empty) { _contentText = input.Text + @"<br />"; input.Text = String.Empty; DisplayContent.Text = this.ContentText; } } } }
コード例の 3 番目の部分は Web ページです。このページの <asp:catalogzone> 要素は、2 つの CatalogPart コントロールの宣言を含んでいます。これらのコントロールは、Button1_Click メソッドの実行時に作成されるカスタム CatalogPartCollection オブジェクトの一部になります。PageCatalogPart コントロールは、以前の実行時にユーザーによって閉じられた Web サーバー コントロールを含んでいます。PageCatalogPart コントロール内のコントロールは、再びページに追加できます。DeclarativeCatalogPart コントロールは、カスタム TextDisplayWebPart コントロールの宣言を含んでいます。ページがカタログ モードになっている場合、ユーザーは、通常のブラウズ モードで使用できるよう、TextDisplayWebPart コントロールをページに追加できます。
<%@ Page Language="vb" %> <%@ register TagPrefix="uc1" TagName="DisplayModeMenuVB" Src="DisplayModeMenuVB.ascx" %> <%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="TextDisplayWebPartVB" %> <script runat="server"> 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 </script> <html > <head id="Head1" runat="server"> </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>
<%@ Page Language="C#" %> <%@ register TagPrefix="uc1" TagName="DisplayModeMenuCS" Src="DisplayModeMenuCS.ascx" %> <%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="TextDisplayWebPartCS" %> <script runat="server"> 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; } </script> <html > <head id="Head1" runat="server"> </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>
ブラウザでページを読み込む場合、[Display Mode] ドロップダウン リスト コントロールで [カタログ] を選択することにより、ページをカタログ モードに切り替えることができます。カスタム WebPart コントロールの横のチェック ボックスをオンにし、 [追加] をクリックするとそのコントロールをページに追加できます。[閉じる] をクリックして、ページをブラウズ モードに戻します。追加したコントロールで、動詞メニュー (タイトル バーに表示される下向きの矢印) をクリックして [閉じる] をクリックすると、そのコントロールがページから削除されて PageCatalogPart コントロールに追加されます。ページをカタログ モードに戻し、[ページ カタログ] リンクをクリックして PageCatalogPart コントロールの内容を表示します。閉じられたコントロールが表示されます。[Display CatalogPart Properties] ボタンをクリックすると、CatalogPartCollection オブジェクトにアクセスします。さらに、格納されている CatalogPart コントロールの特定のプロパティが表示されます。
継承階層
System.Collections.ReadOnlyCollectionBase
System.Web.UI.WebControls.WebParts.CatalogPartCollection
プラットフォーム
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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
Weblioに収録されているすべての辞書からCatalogPartCollection クラスを検索する場合は、下記のリンクをクリックしてください。
全ての辞書からCatalogPartCollection クラスを検索
- CatalogPartCollection クラスのページへのリンク