共用方式為


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

範例

下列程式代碼範例示範如何使用物件的索引來存取對象的成員 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 

當您在瀏覽器中載入頁面時,您可以在 [顯示模式] 下拉式清單控制項中選取 [目錄],將頁面切換為目錄模式。 按兩下 [ 顯示目錄元件屬性 ] 按鈕會存取物件, CatalogPartCollection 並顯示自主 CatalogPart 控制件的特定屬性。 控制項內 PageCatalogPart 可用的伺服器控制項計數是使用 Item[] 方法中的 Button1_Click 索引器來取得。

備註

索引Item[]器可讓您依索引存取物件中的CatalogPartCollection基礎CatalogPart控件,並變更其屬性值或呼叫方法。

另請參閱

適用於

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 的唯一識別碼。

屬性值

在集合中,ID 等於 id 值的第一個 CatalogPart

範例

下列程式代碼範例示範如何使用物件的字串標識碼來存取物件的成員 CatalogPartCollection 。 如需執行範例所需的完整程式碼,請參閱類別概觀主題的 CatalogPartCollection 範例一節。

方法中的Button1_Click程式代碼會建立名為 myParts的新CatalogPartCollection物件。 方法會 Item[] 使用索引器來擷取控件的相關信息 DeclarativeCatalogPart ,這是集合的第二個成員。

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 

當您在瀏覽器中載入頁面時,您可以在 [顯示模式] 下拉式清單控制項中選取 [目錄],將頁面切換為目錄模式。 按兩下 [ 顯示目錄元件屬性 ] 按鈕會存取物件, CatalogPartCollection 並顯示自主 CatalogPart 控制件的特定屬性。 控制項內 DeclarativeCatalogPart 可用的伺服器控制項計數是使用 Item[] 方法中的 Button1_Click 索引器來取得。

備註

索引Item[]器可讓您使用字元串標識符來存取 物件中CatalogPartCollection的基礎CatalogPart控制件。 CatalogPartCollection雖然對像是只讀的,但是您可以在索引器所存取的基礎控件上變更屬性值或呼叫方法。

另請參閱

適用於