EditorPartCollection 클래스

정의

컨트롤의 EditorPart 속성, 레이아웃, 모양 및 동작을 편집하는 데 사용되는 컨트롤 컬렉션을 WebPart 포함합니다. 이 클래스는 상속할 수 없습니다.

public ref class EditorPartCollection sealed : System::Collections::ReadOnlyCollectionBase
public sealed class EditorPartCollection : System.Collections.ReadOnlyCollectionBase
type EditorPartCollection = class
    inherit ReadOnlyCollectionBase
Public NotInheritable Class EditorPartCollection
Inherits ReadOnlyCollectionBase
상속
EditorPartCollection

예제

다음 코드 예제에서는 클래스의 여러 사용을 보여 줍니다 EditorPartCollection . 이 코드 예제에는 다음과 같은 네 가지 부분이 있습니다.

  • 웹 파트 페이지에서 표시 모드를 변경할 수 있는 사용자 컨트롤입니다.

  • 웹 페이지에서 참조되고 컨트롤에서 편집되는 사용자 WebPart지정 TextDisplayWebPart 컨트롤의 EditorPart 클래스입니다.

  • 컨트롤을 TextDisplayWebPart 참조하고, 영역에 선언된 웹 파트 컨트롤 집합의 EditorZone 여러 컨트롤이 있는 컨트롤을 포함하고EditorPart, 개체를 만들고 조작 EditorPartCollection 하는 일부 이벤트 기반 코드를 포함하는 웹 페이지입니다.

  • 브라우저에서 로드할 때 코드 예제가 작동하는 방식에 대한 설명입니다.

이 코드 예제의 첫 번째 부분은 사용자가 웹 페이지에서 표시 모드를 변경할 수 있도록 하는 사용자 정의 컨트롤입니다. 표시 모드 및 이 컨트롤의 소스 코드에 대한 설명에 대한 자세한 내용은 연습: 웹 파트 페이지에서 표시 모드 변경을 참조하세요.

<%@ control language="C#" classname="DisplayModeMenuCS"%>

<script runat="server">
  
 // Use a field to reference the current WebPartManager.
  WebPartManager _manager;

  void Page_Init(object sender, EventArgs e)
  {
    Page.InitComplete += new EventHandler(InitComplete);
  }  

  void InitComplete(object sender, System.EventArgs e)
  {
    _manager = WebPartManager.GetCurrentWebPartManager(Page);

    String browseModeName = WebPartManager.BrowseDisplayMode.Name;

    // Fill the dropdown with the names of supported display modes.
    foreach (WebPartDisplayMode mode in _manager.SupportedDisplayModes)
    {
      String modeName = mode.Name;
      // Make sure a mode is enabled before adding it.
      if (mode.IsEnabled(_manager))
      {
        ListItem item = new ListItem(modeName, modeName);
        DisplayModeDropdown.Items.Add(item);
      }
    }
  }
 
  // Change the page to the selected display mode.
  void DisplayModeDropdown_SelectedIndexChanged(object sender, 
    EventArgs e)
  {
    String selectedMode = DisplayModeDropdown.SelectedValue;

    WebPartDisplayMode mode = 
      _manager.SupportedDisplayModes[selectedMode];
    if (mode != null)
      _manager.DisplayMode = mode;

  }

  void Page_PreRender(object sender, EventArgs e)
  {
    DisplayModeDropdown.SelectedValue = 
      _manager.DisplayMode.Name;
  }

</script>
<div>
  <asp:Panel ID="Panel1" runat="server" 
    Borderwidth="1" 
    Width="125" 
    BackColor="lightgray"
    Font-Names="Verdana, Arial, Sans Serif" >
  <asp:Label ID="Label1" runat="server" 
    Text=" Display Mode" 
    Font-Bold="true"
    Font-Size="8"
    Width="120" 
    AssociatedControlID="DisplayModeDropdown"/>
  <asp:DropDownList ID="DisplayModeDropdown" 
    runat="server"  
    AutoPostBack="true" 
    Width="120"
    OnSelectedIndexChanged="DisplayModeDropdown_SelectedIndexChanged" />
  </asp:Panel>
</div>
<%@ control language="vb" classname="DisplayModeMenuVB"%>

<script runat="server">
  
' Use a field to reference the current WebPartManager.
Dim _manager As WebPartManager


Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) 
    AddHandler Page.InitComplete, AddressOf InitComplete

End Sub 


Sub InitComplete(ByVal sender As Object, ByVal e As System.EventArgs) 
    _manager = WebPartManager.GetCurrentWebPartManager(Page)
    
    Dim browseModeName As String = _
      WebPartManager.BrowseDisplayMode.Name
    
    ' Fill the dropdown with the names of supported display modes.
    Dim mode As WebPartDisplayMode
    For Each mode In  _manager.SupportedDisplayModes
        Dim modeName As String = mode.Name
        ' Make sure a mode is enabled before adding it.
        If mode.IsEnabled(_manager) Then
        Dim item As New ListItem(modeName, modeName)
            DisplayModeDropdown.Items.Add(item)
        End If
    Next mode

End Sub 
 

' Change the page to the selected display mode.
  Sub DisplayModeDropdown_SelectedIndexChanged(ByVal sender As Object, _
    ByVal e As EventArgs)
    Dim selectedMode As String = DisplayModeDropdown.SelectedValue
    
    Dim mode As WebPartDisplayMode = _
      _manager.SupportedDisplayModes(selectedMode)
    If Not (mode Is Nothing) Then
      _manager.DisplayMode = mode
    End If
 
  End Sub


Sub Page_PreRender(ByVal sender As Object, ByVal e As EventArgs) 
    DisplayModeDropdown.SelectedValue = _manager.DisplayMode.Name

End Sub 

</script>
<div>
  <asp:Panel ID="Panel1" runat="server" 
    Borderwidth="1" 
    Width="125" 
    BackColor="lightgray"
    Font-Names="Verdana, Arial, Sans Serif" >
  <asp:Label ID="Label1" runat="server" 
    Text=" Display Mode" 
    Font-Bold="true"
    Font-Size="8"
    Width="120" 
    AssociatedControlID="DisplayModeDropdown"/>
  <asp:DropDownList ID="DisplayModeDropdown" 
    runat="server"  
    AutoPostBack="true" 
    Width="120"
    OnSelectedIndexChanged="DisplayModeDropdown_SelectedIndexChanged" />
  </asp:Panel>
</div>

코드 예제의 두 번째 부분은 컨트롤입니다 TextDisplayWebPart . 코드 예제를 실행하려면 이 소스 코드를 컴파일해야 합니다. 명시적으로 컴파일하고 결과 어셈블리를 웹 사이트의 Bin 폴더 또는 전역 어셈블리 캐시에 넣을 수 있습니다. 또는 사이트의 App_Code 폴더에 소스 코드를 배치하여 런타임에 동적으로 컴파일할 수 있습니다. 두 가지 컴파일 방법을 모두 보여 주는 연습은 연습 : 사용자 지정 웹 서버 컨트롤 개발 및 사용을 참조하세요.

컨트롤에는 이름이 지정된 ContentText속성이 있습니다. 이 속성은 사용자가 입력란에 입력하는 값을 보유합니다. 이 사용자 지정 속성은 컨트롤이 편집 모드일 때 표준 WebPart 컨트롤 속성과 함께 편집할 수 있습니다.

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:editorzone> 페이지의 요소에는 세 EditorPart 개의 컨트롤에 대한 선언이 포함되어 있습니다. 이러한 컨트롤 중 두 가지는 메서드가 실행될 때 만들어지는 사용자 지정 EditorPartCollection 개체의 Button1_Click 일부가 됩니다.

<%@ page language="c#" %>
<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenu" 
  Src="DisplayModecs.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">

  protected void Button1_Click(object sender, EventArgs e)
  {
    ArrayList list = new ArrayList(2);
    list.Add(AppearanceEditorPart1);
    list.Add(PropertyGridEditorPart1);
    // Pass an ICollection object to the constructor.
    EditorPartCollection myParts = new EditorPartCollection(list);
    foreach (EditorPart editor in myParts)
    {
      editor.BackColor = System.Drawing.Color.LightBlue;
      editor.Description = "My " + editor.DisplayTitle + " editor.";
    }

    // Use the IndexOf property to locate an EditorPart control.
    int propertyGridPart = myParts.IndexOf(PropertyGridEditorPart1);
    myParts[propertyGridPart].ChromeType = PartChromeType.TitleOnly;

    // Use the Contains method to see if an EditorPart exists.
    if(!myParts.Contains(LayoutEditorPart1))
      LayoutEditorPart1.BackColor = System.Drawing.Color.LightYellow;
    
    // Use the CopyTo method to create an array of EditorParts.
    EditorPart[] partArray = new EditorPart[3];
    partArray[0] = LayoutEditorPart1;
    myParts.CopyTo(partArray,1);
    Label1.Text = "<h3>EditorParts in Custom Array</h3>";
    foreach (EditorPart ePart in partArray)
    {
      Label1.Text += ePart.Title + "<br />";
    }

  }

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>
      Text Display WebPart with AppearanceEditorPart
    </title>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:webpartmanager id="WebPartManager1" runat="server" />
      <uc1:DisplayModeMenu ID="DisplayModeMenu1" runat="server" />
      <asp:webpartzone id="zone1" runat="server">
        <zonetemplate>
          <aspSample:TextDisplayWebPart 
            runat="server"   
            id="textwebpart" 
            title = "Text Content WebPart" />          
        </zonetemplate>
      </asp:webpartzone> 
      <asp:EditorZone ID="EditorZone1" runat="server">
        <ZoneTemplate>
          <asp:AppearanceEditorPart ID="AppearanceEditorPart1" 
            runat="server" />
          <asp:LayoutEditorPart ID="LayoutEditorPart1" 
            runat="server" />
          <asp:PropertyGridEditorPart ID="PropertyGridEditorPart1" 
            runat="server" />
        </ZoneTemplate>      
      </asp:EditorZone>
      <asp:Button ID="Button1" runat="server" 
        Text="Create EditorPartCollection" 
        OnClick="Button1_Click" />
      <asp:Label ID="Label1" runat="server" Text="" />
    </form>
  </body>
</html>
<%@ page language="vb" %>
<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenu" 
  Src="DisplayModevb.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">

  Protected Sub Button1_Click(ByVal sender As Object, _
    ByVal e As EventArgs)
    
    Dim list As New ArrayList(2)
    list.Add(AppearanceEditorPart1)
    list.Add(PropertyGridEditorPart1)
    ' Pass an ICollection object to the constructor.
    Dim myParts As New EditorPartCollection(list)
    Dim editor As EditorPart
    For Each editor In myParts
      editor.BackColor = System.Drawing.Color.LightBlue
      editor.Description = "My " + editor.DisplayTitle + " editor."
    Next editor
    
    ' Use the IndexOf property to locate an EditorPart control.
    Dim propertyGridPart As Integer = _
      myParts.IndexOf(PropertyGridEditorPart1)
    myParts(propertyGridPart).ChromeType = PartChromeType.TitleOnly
    
    ' Use the Contains method to see if an EditorPart exists.
    If Not myParts.Contains(LayoutEditorPart1) Then
      LayoutEditorPart1.BackColor = System.Drawing.Color.LightYellow
    End If
    
    ' Use the CopyTo method to create an array of EditorParts.
    Dim partArray(2) As EditorPart
    partArray(0) = LayoutEditorPart1
    myParts.CopyTo(partArray, 1)
    Label1.Text = "<h3>EditorParts in Custom Array</h3>"
    Dim ePart As EditorPart
    For Each ePart In partArray
      Label1.Text += ePart.Title + "<br />"
    Next ePart

  End Sub

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>
      Text Display WebPart with AppearanceEditorPart
    </title>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:webpartmanager id="WebPartManager1" runat="server" />
      <uc1:DisplayModeMenu ID="DisplayModeMenu1" runat="server" />
      <asp:webpartzone id="zone1" runat="server">
        <zonetemplate>
          <aspSample:TextDisplayWebPart 
            runat="server"   
            id="textwebpart" 
            title = "Text Content WebPart" />          
        </zonetemplate>
      </asp:webpartzone> 
      <asp:EditorZone ID="EditorZone1" runat="server">
        <ZoneTemplate>
          <asp:AppearanceEditorPart ID="AppearanceEditorPart1" 
            runat="server" />
          <asp:LayoutEditorPart ID="LayoutEditorPart1" 
            runat="server" />
          <asp:PropertyGridEditorPart ID="PropertyGridEditorPart1" 
            runat="server" />
        </ZoneTemplate>      
      </asp:EditorZone>
      <asp:Button ID="Button1" runat="server" 
        Text="Create EditorPartCollection" 
        OnClick="Button1_Click" />
      <asp:Label ID="Label1" runat="server" Text="" />
    </form>
  </body>
</html>

브라우저에서 페이지를 로드할 때 표시 모드 드롭다운 목록 컨트롤에서 편집 을 선택하여 페이지를 편집 모드 로 전환할 수 있습니다. 컨트롤의 제목 표시 TextDisplayWebPart 줄에서 동사 메뉴(아래쪽 화살표)를 클릭하고 편집 을 클릭하여 컨트롤을 편집할 수 있습니다. 편집용 UI(사용자 인터페이스)가 표시되면 모든 컨트롤을 EditorPart 볼 수 있습니다. EditorPartCollection 만들기 단추를 클릭하여 개체를 조작하는 EditorPart 코드에서 EditorPartCollection 만든 컨트롤에 미치는 영향을 확인합니다. 또한 컨트롤을 PropertyGridEditorPart 통해 사용자 지정 TextDisplayWebPart.ContentText 속성을 편집할 수 있습니다. 속성이 컨트롤의 소스 코드에 특성으로 WebBrowsable 표시되어 있기 때문에 가능합니다. 편집 UI에서 속성 값을 업데이트하는 경우 속성을 업데이트 TextDisplayWebPart.ContentText 하는 효과를 보려면 페이지를 일반 찾아보기 모드로 반환해야 합니다.

설명

클래스는 EditorPartCollection 일반적으로 영역에 포함 된 컨트롤의 EditorPart 집합을 EditorZoneBase 추적 하는 영역에서 사용 되는 컨트롤의 EditorPart 읽기 전용 컬렉션입니다.

웹 파트 페이지가 편집 모드로 전환되고 사용자가 편집할 컨트롤을 선택하면 편집 프로세스가 시작됩니다. 영역은 영역에 포함된 컨트롤로 EditorPartCollection 구성된 새 EditorPart 개체를 만듭니다. 편집 프로세스의 다양한 단계에서 영역은 개체에 액세스하여 컬렉션의 EditorPartCollection 컨트롤과 EditorPart 현재 편집 중인 컨트롤 간에 WebPart 속성 값을 저장하거나 검색합니다.

예를 들어 컨트롤 집합 EditorPartCollection 에 대해 대량 작업을 수행해야 하는 경우 프로그래밍 방식으로 사용할 컨트롤 컬렉션을 만들 EditorPart 수 있습니다. 개체가 EditorPartCollection 읽기 전용이더라도 컬렉션에서 참조되는 기본 컨트롤의 속성을 프로그래밍 방식으로 변경할 수 있습니다.

생성자

Name Description
EditorPartCollection()

클래스의 빈 새 인스턴스를 초기화합니다 EditorPartCollection .

EditorPartCollection(EditorPartCollection, ICollection)

컨트롤 컬렉션과 추가 EditorPartCollection 컨트롤 컬렉션을 EditorPartCollection 전달 EditorPart 하여 클래스의 ICollection 새 인스턴스를 EditorPart 초기화합니다.

EditorPartCollection(ICollection)

컨트롤 컬렉션을 전달하여 클래스의 EditorPartCollectionICollection 새 인스턴스를 EditorPart 초기화합니다.

필드

Name Description
Empty

컬렉션의 정적 읽기 전용 빈 인스턴스를 참조합니다.

속성

Name Description
Count

인스턴스에 포함된 ReadOnlyCollectionBase 요소 수를 가져옵니다.

(다음에서 상속됨 ReadOnlyCollectionBase)
InnerList

인스턴스에 포함된 ReadOnlyCollectionBase 요소 목록을 가져옵니다.

(다음에서 상속됨 ReadOnlyCollectionBase)
Item[Int32]

고유 식별자에 따라 컬렉션의 특정 멤버를 반환합니다.

메서드

Name Description
Contains(EditorPart)

특정 컨트롤이 컬렉션에 있는지 여부를 나타내는 값을 반환합니다.

CopyTo(EditorPart[], Int32)

컬렉션을 컨트롤 배열 EditorPart 에 복사합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 여부를 확인합니다.

(다음에서 상속됨 Object)
GetEnumerator()

인스턴스를 반복하는 열거자를 반환합니다 ReadOnlyCollectionBase .

(다음에서 상속됨 ReadOnlyCollectionBase)
GetHashCode()

기본 해시 함수로 사용됩니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type 가져옵니다.

(다음에서 상속됨 Object)
IndexOf(EditorPart)

컬렉션의 특정 멤버 위치를 반환합니다.

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 요소를 필터링합니다.

적용 대상

추가 정보