Export (0) Print
Expand All

SiteMapDataSource Class

Provides a data source control that Web server controls and other controls can use to bind to hierarchical site map data.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

[ToolboxBitmapAttribute(typeof(SiteMapDataSource))]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class SiteMapDataSource : HierarchicalDataSourceControl, 
	IDataSource, IListSource
<asp:SiteMapDataSource />

The SiteMapDataSource control is a data source to the site map data that is stored by the site map providers that are configured for your site. The SiteMapDataSource enables Web server controls that are not specifically site navigation controls, such as the TreeView, Menu, and DropDownList controls, to bind to hierarchical site map data. You can use these Web server controls to display a site map as a table of contents or to actively navigate a site. Alternatively, you can use the SiteMapPath control, which is designed specifically as a site navigation control and therefore does not need an instance of the SiteMapDataSource control.

The SiteMapDataSource binds to site map data and presents its view based on a specified starting node in the site map hierarchy. By default, it is the root node of the hierarchy but it can also be any node within the hierarchy. The starting node is identified by the values of several SiteMapDataSource properties as follows:

Starting Node

Property Values

The root node of the hierarchy (the default setting).

The StartFromCurrentNode is false.

The StartingNodeUrl is not set.

The node that represents the currently viewed page.

The StartFromCurrentNode is true.

The StartingNodeUrl is not set.

A specific node of the hierarchy.

The StartFromCurrentNode is false.

The StartingNodeUrl is set.

If the StartingNodeOffset property is set to a value other than 0, it affects the starting node and with it the site map data hierarchy that is exposed by the SiteMapDataSource control. The negative or positive integer value of the StartingNodeOffset identifies the number of levels up or down the site map hierarchy from the starting node that is identified by the StartFromCurrentNode and StartingNodeUrl properties to offset the starting node of the subtree that is exposed by data source control.

If the StartingNodeOffset property is set to a negative number -n, the starting node of the subtree that is exposed by the data source control is the ancestor node n hierarchical levels above the identified starting node. If the value n is greater than the number of ancestor levels in the hierarchical tree, the starting node of the subtree is the root node of the site map hierarchy.

If the StartingNodeOffset property is set to a positive number +n, the starting node of the subtree that is exposed is a child node n levels below the identified starting node. Because more than one branch of child nodes might exist in the hierarchy, the SiteMapDataSource attempts to resolve a child node directly on the path between the identified starting node and the node that represents the currently requested page, if possible. If the node that represents the currently requested page is not in the subtree of the identified starting node, the value of the StartingNodeOffset property is ignored. If the node that represents the currently requested page is less than n levels below the identified starting node, the currently requested page node is used as the starting node.

Site map data is retrieved from an SiteMapProvider object, such as XmlSiteMapProvider, which is the default site map provider for ASP.NET. You can specify any provider that is configured for your site to provide the site map data to the SiteMapDataSource and can obtain the list of available providers by accessing the SiteMap.Providers collection.

Like all data source controls, every instance of a SiteMapDataSource is associated with a single helper object, known as a data source view. The SiteMapDataSourceView is a view on the site map data, according to the properties of the data source, and is retrieved by calling the GetHierarchicalView method. The SiteMapDataSourceView maintains the SiteMapNodeCollection object that the controls bind to.

By default, the starting node is the root node of the hierarchy, but you can set the starting node to any node. The starting point can be a node that is relative to the current position in the site map or to an absolute position. You can specify the starting node by setting the StartingNodeUrl property.

The SiteMapDataSource is specialized for navigation data, and does not support common data source operations such as sorting, filtering, paging, caching, or data record operations such as updates, insertions or deletions.

TopicLocation
How to: Localize Site-Map DataBuilding ASP .NET Web Applications
How to: Localize Site-Map DataBuilding ASP .NET Web Applications
Walkthrough: Adding Site Navigation to a Web SiteBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Filtering Site-Map Nodes Based on Security RolesBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Controlling ASP.NET Menus ProgrammaticallyBuilding ASP .NET Web Applications in Visual Studio

The following code example demonstrates how to declaratively bind a TreeView control to a site map using a SiteMapDataSource control. The site map data is retrieved beginning at the root node level.

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
        <form id="form1" runat="server">
            <asp:SiteMapDataSource
                id="SiteMapDataSource1"
                runat="server" />

            <asp:TreeView
                id="TreeView1"
                runat="server"
                DataSourceID="SiteMapDataSource1">
            </asp:TreeView>

        </form>
    </body>
</html>

System.Object
  System.Web.UI.Control
    System.Web.UI.HierarchicalDataSourceControl
      System.Web.UI.WebControls.SiteMapDataSource

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft