Edit

Share via


SiteMapDataSource.StartingNodeOffset Property

Definition

Gets or sets a positive or negative integer offset from the starting node that determines the root hierarchy that is exposed by the data source control.

public:
 virtual property int StartingNodeOffset { int get(); void set(int value); };
public virtual int StartingNodeOffset { get; set; }
member this.StartingNodeOffset : int with get, set
Public Overridable Property StartingNodeOffset As Integer

Property Value

The default is 0, which indicates that the root hierarchy exposed by the SiteMapDataSource is the same as the starting node.

Examples

The following code example demonstrates the effect of the StartingNodeUrl and StartingNodeOffset properties. The example consists of several ASP.NET pages, a master page, master page section, and a Web.sitemap file. The Web.sitemap file defines the hierarchical structure of the site. For this code example, it defines a number of pages identified by unique URLs, such as 1.aspx, 2.aspx, A.aspx, and B.aspx, as follows:

The Site.master page contains the SiteMapDataSource and a TreeView controls inside a ContentPlaceHolder control. It identifies the starting node of the exposed hierarchy as Default.aspx, using the StartingNodeUrl property. The Site.master file is used by the Default.aspx page only.

All other pages, such as 1.aspx, 2.aspx, A.aspx, and so on, use the Section.master master page. This master page is very similar to Site.master, however it contains several SiteMapDataSource controls that you can experiment with. The TreeView control that displays site map data is initially bound to SiteMapDataSource1, which specifies a StartingNodeOffset of 1. This indicates that the parent node of the currently requested page is displayed. If you view page 1.aspx, the hierarchy displayed by the TreeView is A, 1, 2. However, if you view page 4.aspx, the hierarchy is B, 3, 4.

If you change the DataSourceID for the TreeView to SiteMapDataSource2, the TreeView control displays site map data differently. When you use SiteMapDataSource2, the StartFromCurrentNode property is set to true, which means that the site map data is displayed relative to the currently requested page and the StartingNodeOffset property is set to -1, indicating that one level of child nodes is displayed, when possible. When you view the A.aspx page, the hierarchy that is displayed is the hierarchy of the current level, including all siblings, such as B and C. When you view 1.aspx, the parent nodes are no longer displayed.

The following code example demonstrates one of the ASP.NET pages you can use with the other components of this code example.

<%@ Page MasterPageFile="~/Section.master" Title="Untitled Page" %>  

<asp:Content ID="Content1" ContentPlaceHolderID=MainBody Runat=Server>  
  <h2>1.aspx</h2>  
</asp:Content>  

Remarks

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 identified starting node is the node that represents the currently requested page, the StartingNodeOffset is ignored.

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.

The value of the StartingNodeOffset property is stored in view state.

Applies to

See also