SiteMapNodeItem(Int32, SiteMapNodeItemType) 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
使用指定的索引和 SiteMapNodeItem 初始化 SiteMapNodeItemType 類別的新執行個體。
public:
SiteMapNodeItem(int itemIndex, System::Web::UI::WebControls::SiteMapNodeItemType itemType);
public SiteMapNodeItem (int itemIndex, System.Web.UI.WebControls.SiteMapNodeItemType itemType);
new System.Web.UI.WebControls.SiteMapNodeItem : int * System.Web.UI.WebControls.SiteMapNodeItemType -> System.Web.UI.WebControls.SiteMapNodeItem
Public Sub New (itemIndex As Integer, itemType As SiteMapNodeItemType)
參數
- itemIndex
- Int32
Controls 集合中的索引,SiteMapPath 控制項使用這個索引來追蹤 SiteMapNodeItem 物件。
- itemType
- SiteMapNodeItemType
這個 SiteMapNode 所表示的 SiteMapNodeItem 功能型別。
範例
下列程式碼範例示範如何建立 SiteMapNodeItem 物件。 此程式碼範例是針對 類別提供的較大範例的 SiteMapPath 一部分。
private void AddDropDownListAfterCurrentNode(SiteMapNodeItem item) {
SiteMapNodeCollection childNodes = item.SiteMapNode.ChildNodes;
// Only do this work if there are child nodes.
if (childNodes != null) {
// Add another PathSeparator after the CurrentNode.
SiteMapNodeItem finalSeparator =
new SiteMapNodeItem(item.ItemIndex,
SiteMapNodeItemType.PathSeparator);
SiteMapNodeItemEventArgs eventArgs =
new SiteMapNodeItemEventArgs(finalSeparator);
InitializeItem(finalSeparator);
// Call OnItemCreated every time a SiteMapNodeItem is
// created and initialized.
OnItemCreated(eventArgs);
// The pathSeparator does not bind to any SiteMapNode, so
// do not call DataBind on the SiteMapNodeItem.
item.Controls.Add(finalSeparator);
// Create a DropDownList and populate it with the children of the
// CurrentNode. There are no styles or templates that are applied
// to the DropDownList control. If OnSelectedIndexChanged is raised,
// the event handler redirects to the page selected.
// The CurrentNode has child nodes.
DropDownList ddList = new DropDownList();
ddList.AutoPostBack = true;
ddList.SelectedIndexChanged += new EventHandler(this.DropDownNavPathEventHandler);
// Add a ListItem to the DropDownList for every node in the
// SiteMapNodes collection.
foreach (SiteMapNode node in childNodes) {
ddList.Items.Add(new ListItem(node.Title, node.Url));
}
item.Controls.Add(ddList);
}
}
Private Sub AddDropDownListAfterCurrentNode(item As SiteMapNodeItem)
Dim childNodes As SiteMapNodeCollection = item.SiteMapNode.ChildNodes
' Only do this work if there are child nodes.
If Not (childNodes Is Nothing) Then
' Add another PathSeparator after the CurrentNode.
Dim finalSeparator As New SiteMapNodeItem(item.ItemIndex, SiteMapNodeItemType.PathSeparator)
Dim eventArgs As New SiteMapNodeItemEventArgs(finalSeparator)
InitializeItem(finalSeparator)
' Call OnItemCreated every time a SiteMapNodeItem is
' created and initialized.
OnItemCreated(eventArgs)
' The pathSeparator does not bind to any SiteMapNode, so
' do not call DataBind on the SiteMapNodeItem.
item.Controls.Add(finalSeparator)
' Create a DropDownList and populate it with the children of the
' CurrentNode. There are no styles or templates that are applied
' to the DropDownList control. If OnSelectedIndexChanged is raised,
' the event handler redirects to the page selected.
' The CurrentNode has child nodes.
Dim ddList As New DropDownList()
ddList.AutoPostBack = True
AddHandler ddList.SelectedIndexChanged, AddressOf Me.DropDownNavPathEventHandler
' Add a ListItem to the DropDownList for every node in the
' SiteMapNodes collection.
Dim node As SiteMapNode
For Each node In childNodes
ddList.Items.Add(New ListItem(node.Title, node.Url))
Next node
item.Controls.Add(ddList)
End If
End Sub
備註
PathDirection如果 為 RootToCurrent ,您可以在集合結尾 Controls 新增網站導覽階層的每個更深層專案。 不過,如果 PathDirection 屬性設定 CurrentToRoot 為 ,則必須在集合開頭插入每個更深層的 Controls 節點。