WebPartCollection 생성자

정의

WebPartCollection 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the WebPartCollection class.

오버로드

WebPartCollection()

WebPartCollection 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes an empty new instance of the WebPartCollection class.

WebPartCollection(ICollection)

WebPartCollection 컨트롤의 ICollection 컬렉션을 전달하여 WebPart 개체의 새 인스턴스를 초기화합니다.Initializes a new instance of a WebPartCollection object by passing in an ICollection collection of WebPart controls.

WebPartCollection()

WebPartCollection 클래스의 비어 있는 새 인스턴스를 초기화합니다.Initializes an empty new instance of the WebPartCollection class.

public:
 WebPartCollection();
public WebPartCollection ();
Public Sub New ()

설명

합니다 WebPartCollection 생성자의 빈 인스턴스를 초기화 합니다 WebPartCollection 클래스입니다.The WebPartCollection constructor initializes an empty instance of the WebPartCollection class. 개체 자체는 읽기 전용 및 개별 추가할 메서드가 없습니다 WebPart 컨트롤 적용 합니다. 따라서이 생성자를 사용 하는 작은 경우 해야 합니다.The object itself is read-only and has no method to add individual WebPart controls to it; therefore, you will have little occasion to use this constructor.

추가 정보

WebPartCollection(ICollection)

WebPartCollection 컨트롤의 ICollection 컬렉션을 전달하여 WebPart 개체의 새 인스턴스를 초기화합니다.Initializes a new instance of a WebPartCollection object by passing in an ICollection collection of WebPart controls.

public:
 WebPartCollection(System::Collections::ICollection ^ webParts);
public WebPartCollection (System.Collections.ICollection webParts);
new System.Web.UI.WebControls.WebParts.WebPartCollection : System.Collections.ICollection -> System.Web.UI.WebControls.WebParts.WebPartCollection
Public Sub New (webParts As ICollection)

매개 변수

webParts
ICollection

ICollection 컨트롤의 WebPart입니다.An ICollection of WebPart controls.

예외

webPartsnull입니다.webParts is null.

webParts 컬렉션의 개체가 null인 경우An object in the webParts collection is null.

또는-or- webParts 컬렉션의 개체가 WebPart 형식이 아닌 경우An object in the webParts collection is not a of type WebPart.

예제

다음 코드 예제에서는 WebPartCollection 웹 파트 페이지에는 생성자입니다.The following code example demonstrates the use of the WebPartCollection constructor on a Web Parts page. 이 예제는 세 부분으로 이루어져 있습니다.This example has three parts:

  • 코드는 partial 클래스에는 페이지입니다.The code for the page in a partial class.

  • 컨트롤이 들어 있는 웹 페이지입니다.The Web page that contains the controls.

  • 이 예제에서는 브라우저에서 작동 하는 방법의 설명입니다.A description of how the example works in a browser.

첫 번째 부분은 코드 예제에서는 partial 클래스에서 페이지의 코드를 포함합니다.The first part of the code example contains the code for the page in a partial class. Button1_Click 메서드를 만듭니다를 WebPartCollection 구성 된 모든 개체를 WebPart 에서 참조 된 컨트롤을 WebPartManager.WebParts 속성을 모두 포함 하는 WebPart 페이지의 컨트롤입니다.Note that the Button1_Click method creates a WebPartCollection object that consists of all the WebPart controls referenced in the WebPartManager.WebParts property, which includes all the WebPart controls on the page. 메서드는 모든 컨트롤을 반복 하 고 각 컨트롤의 설정/해제 ChromeState 보통 또는 최소화 된 상태로 해당 컨트롤 인지 여부를 결정 하는 속성입니다.The method iterates through all the controls, and toggles each control's ChromeState property, which determines whether that control is normal or minimized.

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class webpartcollectioncs : System.Web.UI.Page
{
  protected void Button1_Click(object sender, EventArgs e)
  {

    WebPartCollection partCollection = mgr1.WebParts;

    foreach (WebPart part in partCollection)
    {
      if (part.ChromeState != PartChromeState.Minimized)
        part.ChromeState = PartChromeState.Minimized;
      else
        part.ChromeState = PartChromeState.Normal;
    }
  }
  protected void Button2_Click(object sender, EventArgs e)
  {
    WebPartCollection partCollection = WebPartZone1.WebParts;

    if (partCollection[0].Title == "My Link List")
      partCollection[0].Title = "Favorite Links";
    else
      partCollection[0].Title = "My Link List";
  }
}
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts

Partial Public Class webpartcollectionvb

  Inherits System.Web.UI.Page

  Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    Dim partCollection As WebPartCollection = mgr1.WebParts
    Dim part As WebPart

    For Each part In partCollection
      If part.ChromeState <> PartChromeState.Minimized Then
        part.ChromeState = PartChromeState.Minimized
      Else
        part.ChromeState = PartChromeState.Normal
      End If
    Next

  End Sub

  Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    Dim partCollection As WebPartCollection = WebPartZone1.WebParts

    If partCollection(0).Title = "My Link List" Then
      partCollection(0).Title = "Favorite Links"
    Else
      partCollection(0).Title = "My Link List"
    End If

  End Sub

End Class

코드 예제의 두 번째 부분은 컨트롤이 들어 있는 웹 페이지입니다.The second part of the code example is the Web page that contains the controls. 컨트롤에 선언 된 WebPartZone1 은 표준 ASP.NET 서버 컨트롤 하지만 래핑되고 GenericWebPart 런타임 시 컨트롤 및 GenericWebPart 클래스에서 상속을 WebPart 클래스 컨트롤은 자동으로 취급 WebPart 컨트롤에서 런타임 및에 포함 된를 WebPartCollection 개체입니다.Notice that the controls declared in WebPartZone1 are standard ASP.NET server controls, but because they are wrapped as GenericWebPart controls at run time, and the GenericWebPart class inherits from the WebPart class, the controls are automatically treated as WebPart controls at run time and therefore are included in the WebPartCollection object.

<%@ Page Language="C#" 
  Codefile="webpartcollection.cs" 
  Inherits="webpartcollectioncs" %>

<!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 runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:WebPartManager ID="mgr1" 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>
          <br />
          <asp:Calendar ID="Calendar1" runat="server" 
            Title="My Calendar" />
        </ZoneTemplate>
      </asp:WebPartZone>
    </div>
    <hr />
    <asp:Button ID="Button1" runat="server" Width="200"
      Text="Toggle ChromeState" OnClick="Button1_Click" />
    <br />
    <asp:Button ID="Button2" runat="server" Width="200"
        Text="Toggle BulletedList1 Title" 
        OnClick="Button2_Click"/>
    </form>
</body>
</html>
<%@ Page Language="vb"
  Codefile="webpartcollection.vb" 
  Inherits="webpartcollectionvb" %>

<!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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:WebPartManager ID="mgr1" 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>
          <br />
          <asp:Calendar ID="Calendar1" runat="server" 
            Title="My Calendar" />
        </ZoneTemplate>
      </asp:WebPartZone>
    </div>
    <hr />
    <asp:Button ID="Button1" runat="server" Width="200"
      Text="Toggle ChromeState" OnClick="Button1_Click" />
    <br />
    <asp:Button ID="Button2" runat="server" Width="200"
        Text="Toggle BulletedList1 Title" 
        OnClick="Button2_Click"/>
    </form>
</body>
</html>

브라우저에서 페이지를 로드 한 후 클릭 합니다 토글 ChromeState 단추를 클릭 한 partial 클래스의 코드 반복을 확인할 수 있습니다는 WebPartCollection 개체 또는 컨트롤을 최소화 하거나 일반에 게 반환 합니다.After you load the page in a browser, click the Toggle ChromeState button, and notice that the code in the partial class loops through the WebPartCollection object and alternately minimizes the controls or returns them to normal. 또는 반복 해 서 클릭 합니다 BulletedList1 제목 설정/해제 단추 위 컨트롤의 제목을 대체 값으로 변경 됩니다.Or, if you repeatedly click the Toggle BulletedList1 Title button, the title of the uppermost control is changed to alternate values.

설명

합니다 WebPartCollection 생성자의 인스턴스를 초기화 합니다 WebPartCollection 클래스의 컬렉션을 전달 하 여 WebPart 컨트롤입니다.The WebPartCollection constructor initializes an instance of the WebPartCollection class by passing in a collection of WebPart controls.

하지만 WebPartCollection 개체는 읽기 전용 및 개별 컨트롤을 추가 하는 것에 대 한 메서드가 없는, 직접 만들 수 있습니다 ICollection 컨트롤의 컬렉션에 전달 하 고는 WebPartCollection 생성자입니다.Although a WebPartCollection object is read-only and there is no method for adding individual controls to it, you can create your own ICollection collection of controls, and pass that to the WebPartCollection constructor. 이 옵션을 사용 하면 사용자 지정 컬렉션을 만들고 대량 작업을 수행할 수 있습니다.This enables you to create custom collections and perform bulk operations on them. 또한 기본 컨트롤 컬렉션에 액세스 하 고 해당 속성 값을 프로그래밍 방식으로 변경할 수 있습니다.You can also access the underlying controls in the collection and change their property values programmatically.

추가 정보

적용 대상