SiteMapNodeItem Class
Assembly: System.Web (in system.web.dll)
The SiteMapPath control is a CompositeControl, which means it renders a user interface composed of many other Web server controls. While the SiteMapPath control works directly with the SiteMap configured for your site and its SiteMapNode objects, the SiteMapNode objects are not Web server controls. The SiteMapNodeItem class is a Web server control wrapper for the SiteMapNode class, which enables the SiteMapPath control to display SiteMapNode data while maintaining the functional distinction between a generic navigation data item and a user interface item.
The SiteMapPath control maintains the site map nodes in its Controls collection internally. Because the SiteMapPath can render its child controls with different styles, templates, and orders, it must be able to distinguish between functionally different types of nodes, regardless of display order. For this reason, each SiteMapNodeItem is created with a specific type. (Possible types are listed in the SiteMapNodeItemType enumeration.)
Use the SiteMapNodeItem class directly in your code only if you plan to extend the SiteMapPath control or write a control with similar functionality.
The following code example demonstrates how to create and manipulate SiteMapNodeItem objects within the InitializeItem method of a class that derives from SiteMapPath. This code example is part of a larger example provided for the SiteMapPath class.
private void AddDropDownListAfterCurrentNode(SiteMapNodeItem item)
{
SiteMapNodeCollection childNodes = item.get_SiteMapNode().
get_ChildNodes();
// Only do this work if there are child nodes.
if (childNodes != null) {
// Add another PathSeparator after the CurrentNode.
SiteMapNodeItem finalSeparator = new SiteMapNodeItem(item.
get_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.get_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.set_AutoPostBack(true);
ddList.add_SelectedIndexChanged(new EventHandler(this.
DropDownNavPathEventHandler));
// Add a ListItem to the DropDownList for every node in the
// SiteMapNodes collection.
for (int iCtr = 0; iCtr < childNodes.get_Count(); iCtr++) {
SiteMapNode node = (SiteMapNode)childNodes.get_Item(iCtr);
ddList.get_Items().Add(new ListItem(node.get_Title(), node.
get_Url()));
}
item.get_Controls().Add(ddList);
}
} //AddDropDownListAfterCurrentNode
- AspNetHostingPermission for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
System.Web.UI.Control
System.Web.UI.WebControls.WebControl
System.Web.UI.WebControls.SiteMapNodeItem