CatalogPartCollection.Item[] 属性

定义

根据位置或唯一标识符返回集合中的特定成员。Returns a specific member of the collection according to its position or a unique identifier.

重载

Item[Int32]

基于集合中的位置获取或设置集合的成员。Gets or sets a member of the collection, based on its position in the collection.

Item[String]

基于唯一字符串标识符返回集合的成员。Returns a member of the collection based on a unique string identifier.

Item[Int32]

基于集合中的位置获取或设置集合的成员。Gets or sets a member of the collection, based on its position in the collection.

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 的索引。The index of a particular CatalogPart in the collection.

属性值

CatalogPart

位于集合中指定索引处的 CatalogPartA CatalogPart at the specified index in the collection.

示例

下面的代码示例演示如何使用对象的索引来访问该 CatalogPartCollection 对象的成员。The following code example demonstrates how you can access a member of a CatalogPartCollection object using its index. 有关运行此示例所需的完整代码,请参阅类概述主题的 "示例" 部分 CatalogPartCollectionFor the full code required to run the example, see the Example section of the CatalogPartCollection class overview topic.

方法中的代码 Button1_Click 创建一个 CatalogPartCollection 名为的新对象 myPartsThe code in the Button1_Click method creates a new CatalogPartCollection object named myParts. 请注意,该方法使用 Item[] 索引器从集合的第一个成员中检索信息。Note that the method uses the Item[] indexer to retrieve information from the first member of the collection.

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 

在浏览器中加载页面时,可以通过在 "显示模式" 下拉列表控件中选择 "目录",将页面切换到目录模式。When you load the page in a browser, you can switch the page into catalog mode by selecting Catalog in the Display Mode drop-down list control. 单击 " 显示 CatalogPart 属性 " 按钮将访问 CatalogPartCollection 对象并显示所包含控件的某些属性 CatalogPartClicking the Display CatalogPart Properties button accesses the CatalogPartCollection object and displays certain properties of the contained CatalogPart controls. PageCatalogPart使用方法中的索引器可获取控件内可用服务器控件的计数 Item[] Button1_ClickThe count of available server controls within the PageCatalogPart control is obtained by using the Item[] indexer in the Button1_Click method.

注解

使用索引 Item[] 器可以 CatalogPart 按索引访问对象中的基础控件 CatalogPartCollection ,并可以更改其属性值或调用方法。The Item[] indexer allows you to access the underlying CatalogPart controls in a CatalogPartCollection object by index, and change their property values or call methods.

适用于

Item[String]

基于唯一字符串标识符返回集合的成员。Returns a member of the collection based on a unique string identifier.

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 的唯一标识符。The unique identifier for a particular CatalogPart in a collection.

属性值

CatalogPart

集合中 ID 等于 id 的值的第一个 CatalogPartThe first CatalogPart in the collection whose ID equals the value of id.

示例

下面的代码示例演示如何 CatalogPartCollection 使用对象的字符串 ID 值访问该对象的成员。The following code example demonstrates how you can access a member of a CatalogPartCollection object using its string ID value. 有关运行此示例所需的完整代码,请参阅类概述主题的 "示例" 部分 CatalogPartCollectionFor the full code required to run the example, see the Example section of the CatalogPartCollection class overview topic.

方法中的代码 Button1_Click 创建一个 CatalogPartCollection 名为的新对象 myPartsThe code in the Button1_Click method creates a new CatalogPartCollection object named myParts. 方法使用 Item[] 索引器检索有关控件的信息 DeclarativeCatalogPart ,这是集合的第二个成员。The method uses the Item[] indexer to retrieve information about the DeclarativeCatalogPart control, which is the second member of the collection.

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 

在浏览器中加载页面时,可以通过在 "显示模式" 下拉列表控件中选择 "目录",将页面切换到目录模式。When you load the page in a browser, you can switch the page into catalog mode by selecting Catalog in the Display Mode drop-down list control. 单击 " 显示 CatalogPart 属性 " 按钮将访问 CatalogPartCollection 对象并显示所包含控件的某些属性 CatalogPartClicking the Display CatalogPart Properties button accesses the CatalogPartCollection object and displays certain properties of the contained CatalogPart controls. DeclarativeCatalogPart使用方法中的索引器可获取控件内可用服务器控件的计数 Item[] Button1_ClickThe count of available server controls within the DeclarativeCatalogPart control is obtained by using the Item[] indexer in the Button1_Click method.

注解

Item[]索引器允许您 CatalogPart CatalogPartCollection 通过使用字符串标识符来访问对象中的基础控件。The Item[] indexer allows you to access the underlying CatalogPart controls in a CatalogPartCollection object by use of a string identifier. 尽管 CatalogPartCollection 对象是只读的,但您可以更改属性值或调用索引器访问的基础控件上的方法。Although the CatalogPartCollection object is read-only, you can change the property values or call methods on the underlying controls accessed by the indexer.

适用于