SiteMapNodeItem.ItemIndex 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
检索 SiteMapPath 控件用于在其内部集合中跟踪和管理 SiteMapNodeItem 的索引。
public:
virtual property int ItemIndex { int get(); };
public virtual int ItemIndex { get; }
member this.ItemIndex : int
Public Overridable ReadOnly Property ItemIndex As Integer
属性值
一个整数,表示 SiteMapNodeItem 在 SiteMapPath 控件的内部集合中的位置。
示例
下面的代码示例演示如何获取 ItemIndex 属性并使用它来创建 SiteMapNodeItem 路径分隔符。 PathSeparator 节点项是在与上一个节点相同的索引处创建的。 此代码示例是为 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