WebPartCollection.Item[] 속성

정의

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

오버로드

Item[Int32]

컬렉션에서의 위치를 기준으로 컬렉션의 멤버를 반환합니다.

Item[String]

고유한 문자열 식별자를 기반으로 컬렉션의 멤버를 반환합니다.

Item[Int32]

컬렉션에서의 위치를 기준으로 컬렉션의 멤버를 반환합니다.

public:
 property System::Web::UI::WebControls::WebParts::WebPart ^ default[int] { System::Web::UI::WebControls::WebParts::WebPart ^ get(int index); };
public System.Web.UI.WebControls.WebParts.WebPart this[int index] { get; }
member this.Item(int) : System.Web.UI.WebControls.WebParts.WebPart
Default Public ReadOnly Property Item(index As Integer) As WebPart

매개 변수

index
Int32

컬렉션에 있는 특정 WebPart 컨트롤의 인덱스입니다.

속성 값

컬렉션의 지정된 인덱스에 있는 WebPart입니다.

예제

다음 코드 예제에서는 웹 파트 페이지에서 인덱서의 Item[] 사용을 보여 줍니다. 이 예제에는 다음 세 부분이 있습니다.

  • partial 클래스의 페이지에 대한 코드입니다.

  • 컨트롤이 포함된 웹 페이지입니다.

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

코드 예제의 첫 번째 부분에는 partial 클래스의 페이지에 대한 코드가 포함되어 있습니다. 메서드는 Button2_ClickWebPartCollection 개체를 만든 다음 속성의 컨트롤을 WebPart 할당합니다 WebPartZone1.WebParts . 메서드는 인덱스를 사용하여 컬렉션의 첫 번째 컨트롤에 액세스하고 해당 속성 값을 토글합니다 Title .

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

코드 예제의 두 번째 부분은 컨트롤을 포함하는 웹 페이지입니다. 에 WebPartZone1 선언된 컨트롤은 표준 ASP.NET 서버 컨트롤이지만 런타임에 컨트롤로 GenericWebPart 래핑되고 GenericWebPart 클래스가 클래스에서 WebPart 상속되므로 컨트롤을 런타임에 컨트롤로 WebPart 처리하고 개체의 WebPartCollection 일부로 만들 수 있습니다.

<%@ 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>

브라우저에서 페이지를 로드한 후 글머리 기호 목록1 제목 설정/해제 단추를 클릭하고 코드가 사용 가능한 두 타이틀 선택 항목 간에 컨트롤의 제목을 토글하는 것을 확인합니다.

설명

Item[] 덱서는 인덱스를 통해 개체의 기본 WebPart 컨트롤에 WebPartCollection 액세스하고 해당 속성 값 또는 호출 메서드를 변경할 수 있습니다.

추가 정보

적용 대상

Item[String]

고유한 문자열 식별자를 기반으로 컬렉션의 멤버를 반환합니다.

public:
 property System::Web::UI::WebControls::WebParts::WebPart ^ default[System::String ^] { System::Web::UI::WebControls::WebParts::WebPart ^ get(System::String ^ id); };
public System.Web.UI.WebControls.WebParts.WebPart this[string id] { get; }
member this.Item(string) : System.Web.UI.WebControls.WebParts.WebPart
Default Public ReadOnly Property Item(id As String) As WebPart

매개 변수

id
String

컬렉션의 특정 WebPart 컨트롤에 대한 고유한 식별자입니다.

속성 값

컬렉션에서 ID가 id 값과 동일한 첫 번째 WebPart입니다.

설명

Item[] 덱서에서는 고유 식별자에 따라 개체의 WebPartCollection 컨트롤에 액세스할 WebPart 수 있습니다.

참고

웹 파트 컨트롤 집합은 이 속성에서 대/소문자를 구분하지 않는 일치를 수행하므로 대/소문자 구분이 고유 id 값의 일부가 아닙니다.

속성은 Item[] 일부 특수한 경우에 개체의 멤버를 WebPartCollection 식별하기 위해 작동합니다. 컨트롤의 GenericWebPart 경우 인덱서는 컨트롤에 의해 GenericWebPart 래핑된 기본 자식 컨트롤의 식별자를 일치시킬 수 있습니다. 컨트롤의 ProxyWebPart 경우 인덱서는 매개 변수와 OriginalID 또는 GenericWebPartID 속성 값의 대/소문자를 구분하지 않는 비교를 기반으로 컨트롤의 id 식별자와 일치합니다.

추가 정보

적용 대상