CatalogPartCollection.Item[] 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
根据位置或唯一标识符返回集合中的特定成员。
重载
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。
示例
下面的代码示例演示如何使用对象的字符串 ID 值访问对象的成员 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 是只读的,但可以更改属性值或调用索引器访问的基础控件的方法。