CatalogPartCollection 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
최종 사용자가 웹 페이지에 추가할 수 있는 웹 서버 컨트롤의 카탈로그를 제공하는 데 사용되는 컨트롤 컬렉션을 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 . 이 코드 예제에는 다음과 같은 네 가지 부분이 있습니다.
웹 파트 페이지에서 표시 모드를 변경할 수 있는 사용자 컨트롤입니다.
웹 페이지에서 참조되고 컨트롤 중 하나에 포함된 사용자 WebPart지정
TextDisplayWebPart컨트롤의 CatalogPart 클래스입니다.컨트롤을
TextDisplayWebPart참조하고, 영역에 선언된 웹 파트 컨트롤 집합의 컨트롤 두 CatalogZone 개를 포함하는 컨트롤을 포함하고CatalogPart, 개체를 만들고 조작 CatalogPartCollection 하는 이벤트 기반 코드를 포함하는 웹 페이지입니다.브라우저에서 로드할 때 코드 예제가 작동하는 방식에 대한 설명입니다.
코드 예제의 첫 번째 부분은 사용자 컨트롤입니다. 사용자 컨트롤의 소스 코드는 다른 항목에서 제공됩니다. 이 코드 예제가 작동하려면 연습 : 웹 파트 페이지의 표시 모드 변경 항목에서 사용자 컨트롤에 대한 .ascx 파일을 가져와서 이 코드 예제의 .aspx 페이지와 동일한 폴더에 배치해야 합니다.
코드 예제의 두 번째 부분은 컨트롤입니다 TextDisplayWebPart . 코드 예제를 실행하려면 이 소스 코드를 컴파일해야 합니다. 명시적으로 컴파일하고 결과 어셈블리를 웹 사이트의 Bin 폴더 또는 전역 어셈블리 캐시에 넣을 수 있습니다. 또는 사이트의 App_Code 폴더에 소스 코드를 배치하여 런타임에 동적으로 컴파일할 수 있습니다. 두 가지 컴파일 방법을 모두 보여 주는 연습은 연습 : 사용자 지정 웹 서버 컨트롤 개발 및 사용을 참조하세요. 컨트롤에는 이름이 지정된 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
코드 예제의 세 번째 부분은 웹 페이지입니다.
<asp:catalogzone> 페이지의 요소에는 두 컨트롤 CatalogPart 에 대한 선언이 포함되어 있습니다. 이러한 컨트롤은 메서드가 실행될 때 만들어지는 사용자 지정 CatalogPartCollection 개체의 Button1_Click 일부가 됩니다. 컨트롤에는 PageCatalogPart 런타임에 사용자가 이전에 닫은 웹 서버 컨트롤이 포함되어 있습니다. 컨트롤의 컨트롤을 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 읽기 전용 컬렉션입니다.
웹 파트 페이지가 카탈로그 모드로 전환되면 영역은 컨트롤로 구성된 새 CatalogPartCollection 개체를 CatalogPart 만듭니다. 컬렉션의 각 CatalogPart 컨트롤에는 사용 가능한 서버 컨트롤 카탈로그 형식으로 표시되는 0개 이상의 웹 서버 컨트롤에 대한 참조가 포함될 수 있습니다.
예를 들어 컨트롤 집합 CatalogPartCollection 에 대해 대량 작업을 수행해야 하는 경우 프로그래밍 방식으로 사용할 컨트롤 컬렉션을 만들 CatalogPart 수 있습니다. 개체가 CatalogPartCollection 읽기 전용이더라도 컬렉션에서 참조되는 기본 컨트롤을 프로그래밍 방식으로 변경할 수 있습니다.
생성자
| Name | Description |
|---|---|
| CatalogPartCollection() |
클래스의 빈 새 인스턴스를 초기화합니다 CatalogPartCollection . |
| CatalogPartCollection(CatalogPartCollection, ICollection) |
영역에 있는 기존 CatalogPartCollection 컨트롤의 ICollection 컬렉션과 추가 컨트롤 컬렉션을 전달 CatalogPart 하여 클래스의 새 인스턴스를 초기화합니다. |
| CatalogPartCollection(ICollection) |
컨트롤 컬렉션을 전달하여 클래스의 CatalogPartCollectionICollection 새 인스턴스를 CatalogPart 초기화합니다. |
필드
| Name | Description |
|---|---|
| Empty |
컬렉션의 정적 읽기 전용 빈 인스턴스를 참조합니다. |
속성
| Name | Description |
|---|---|
| Count |
인스턴스에 포함된 ReadOnlyCollectionBase 요소 수를 가져옵니다. (다음에서 상속됨 ReadOnlyCollectionBase) |
| InnerList |
인스턴스에 포함된 ReadOnlyCollectionBase 요소 목록을 가져옵니다. (다음에서 상속됨 ReadOnlyCollectionBase) |
| Item[Int32] |
컬렉션의 위치에 따라 컬렉션의 멤버를 가져오거나 설정합니다. |
| Item[String] |
고유한 문자열 식별자를 기반으로 컬렉션의 멤버를 반환합니다. |
메서드
| Name | Description |
|---|---|
| Contains(CatalogPart) |
컬렉션에 특정 컨트롤이 있는지 여부를 나타내는 값을 반환합니다. |
| CopyTo(CatalogPart[], Int32) |
컬렉션을 개체 배열 CatalogPart 에 복사합니다. |
| Equals(Object) |
지정된 개체가 현재 개체와 같은지 여부를 확인합니다. (다음에서 상속됨 Object) |
| GetEnumerator() |
인스턴스를 반복하는 열거자를 반환합니다 ReadOnlyCollectionBase . (다음에서 상속됨 ReadOnlyCollectionBase) |
| GetHashCode() |
기본 해시 함수로 사용됩니다. (다음에서 상속됨 Object) |
| GetType() |
현재 인스턴스의 Type 가져옵니다. (다음에서 상속됨 Object) |
| IndexOf(CatalogPart) |
컬렉션의 특정 멤버 위치를 반환합니다. |
| MemberwiseClone() |
현재 Object단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
| ToString() |
현재 개체를 나타내는 문자열을 반환합니다. (다음에서 상속됨 Object) |
명시적 인터페이스 구현
| Name | Description |
|---|---|
| ICollection.CopyTo(Array, Int32) |
대상 배열의 지정된 인덱스에서 시작하여 호환되는 1차원ReadOnlyCollectionBase으로 전체를 Array 복사합니다. (다음에서 상속됨 ReadOnlyCollectionBase) |
| ICollection.IsSynchronized |
개체에 대한 액세스 ReadOnlyCollectionBase 가 동기화되는지 여부를 나타내는 값을 가져옵니다(스레드로부터 안전). (다음에서 상속됨 ReadOnlyCollectionBase) |
| ICollection.SyncRoot |
개체에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 ReadOnlyCollectionBase 가져옵니다. (다음에서 상속됨 ReadOnlyCollectionBase) |
확장명 메서드
| Name | Description |
|---|---|
| AsParallel(IEnumerable) |
쿼리의 병렬 처리를 사용하도록 설정합니다. |
| AsQueryable(IEnumerable) |
IEnumerable IQueryable변환합니다. |
| Cast<TResult>(IEnumerable) |
IEnumerable 요소를 지정된 형식으로 캐스팅합니다. |
| OfType<TResult>(IEnumerable) |
지정된 형식에 따라 IEnumerable 요소를 필터링합니다. |