CatalogPartCollection.Item[] プロパティ

定義

コレクションにおける位置または一意の識別子に基づいて特定のメンバーを返します。

オーバーロード

Item[Int32]

コレクション内の位置に基づいて、コレクションのメンバーを取得または設定します。

Item[String]

一意の文字列識別子に基づいて、コレクションのメンバーを返します。

Item[Int32]

コレクション内の位置に基づいて、コレクションのメンバーを取得または設定します。

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

パラメーター

index
Int32

特定の CatalogPart の、コレクション内でのインデックス。

プロパティ値

CatalogPart

コレクション内の指定したインデックス位置にある CatalogPart

次のコード例は、インデックスを使用してオブジェクトのメンバーにアクセスする方法を CatalogPartCollection 示しています。 この例を実行するために必要な完全なコードについては、クラス概要トピックの「例」セクションを CatalogPartCollection 参照してください。

メソッドのコードは、Button1_Clickという名前myPartsの新しいCatalogPartCollectionオブジェクトを作成します。 このメソッドでは、インデクサーを Item[] 使用してコレクションの最初のメンバーから情報を取得します。

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;
}
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 

ブラウザーでページを読み込むときは、[表示モード] ドロップダウン リスト コントロールで [カタログ] を選択することで、ページを カタログ モードに 切り替えることができます。 [ CatalogPart プロパティの表示 ] ボタンをクリックすると、オブジェクトに CatalogPartCollection アクセスし、含まれている CatalogPart コントロールの特定のプロパティが表示されます。 コントロール内PageCatalogPartで使用可能なサーバー コントロールの数は、メソッドのインデクサーをItem[]Button1_Click使用して取得されます。

注釈

Item[]インデクサーを使用すると、インデックスによってオブジェクト内の基になるCatalogPartコントロールにCatalogPartCollectionアクセスし、そのプロパティ値または呼び出しメソッドを変更できます。

こちらもご覧ください

適用対象

Item[String]

一意の文字列識別子に基づいて、コレクションのメンバーを返します。

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

パラメーター

id
String

コレクション内の特定の CatalogPart の一意の識別子。

プロパティ値

CatalogPart

ID が id の値に等しい、コレクション内の最初の CatalogPart

次のコード例は、文字列 ID 値を使用してオブジェクトの CatalogPartCollection メンバーにアクセスする方法を示しています。 この例を実行するために必要な完全なコードについては、クラス概要トピックの「例」セクションを CatalogPartCollection 参照してください。

メソッドのコードは、Button1_Clickという名前myPartsの新しいCatalogPartCollectionオブジェクトを作成します。 このメソッドは、インデクサーを Item[] 使用して、コレクションの DeclarativeCatalogPart 2 番目のメンバーであるコントロールに関する情報を取得します。

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;
}
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 

ブラウザーでページを読み込むときは、[表示モード] ドロップダウン リスト コントロールで [カタログ] を選択することで、ページを カタログ モードに 切り替えることができます。 [ CatalogPart プロパティの表示 ] ボタンをクリックすると、オブジェクトに CatalogPartCollection アクセスし、含まれている CatalogPart コントロールの特定のプロパティが表示されます。 コントロール内DeclarativeCatalogPartで使用可能なサーバー コントロールの数は、メソッドのインデクサーをItem[]Button1_Click使用して取得されます。

注釈

インItem[]デクサーを使用すると、文字列識別子を使用して、オブジェクト内CatalogPartCollectionの基になるCatalogPartコントロールにアクセスできます。 CatalogPartCollectionオブジェクトは読み取り専用ですが、プロパティ値を変更したり、インデクサーによってアクセスされる基になるコントロールのメソッドを呼び出したりできます。

こちらもご覧ください

適用対象