CatalogPartCollection.Item[] 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
根據集合的位置或唯一識別碼回傳特定成員。
多載
| 名稱 | Description |
|---|---|
| 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 事物的索引。
屬性值
A CatalogPart 位於集合中指定的索引。
範例
以下程式碼範例示範如何利用物件的索引存取物件的 CatalogPartCollection 成員。 關於執行範例所需的完整程式碼,請參閱課程總覽主題的 CatalogPartCollection 範例部分。
該方法中的 Button1_Click 程式碼會建立一個 CatalogPartCollection 名為 myParts的新物件。 請注意,此方法使用 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[]索引器允許你透過索引存取物件底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值的集合。
範例
以下程式碼範例示範如何利用物件的字串 ID 值存取物件成員 CatalogPartCollection 。 關於執行範例所需的完整程式碼,請參閱課程總覽主題的 CatalogPartCollection 範例部分。
該方法中的 Button1_Click 程式碼會建立一個 CatalogPartCollection 名為 myParts的新物件。 此方法利用 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[]索引器允許你透過字串識別碼存取物件中的CatalogPart底層CatalogPartCollection控制項。 雖然物件 CatalogPartCollection 是唯讀,但你可以更改索引器存取的底層控制項的屬性值或呼叫方法。