SiteMapDataSource.StartingNodeOffset 属性

定义

获取或设置一个从起始节点开始计算的正整数或负整数偏移量,该起始节点确定了由数据源控件公开的根层次结构。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

属性值

Int32

默认值为 0,它指示由 SiteMapDataSource 公开的根层次结构与起始节点相同。The default is 0, which indicates that the root hierarchy exposed by the SiteMapDataSource is the same as the starting node.

示例

下面的代码示例演示了 StartingNodeUrl 和属性的效果 StartingNodeOffsetThe following code example demonstrates the effect of the StartingNodeUrl and StartingNodeOffset properties. 该示例包含多个 ASP.NET 页、一个母版页、一个母版页部分和一个 web.sitemap 文件。The example consists of several ASP.NET pages, a master page, master page section, and a Web.sitemap file. Web.sitemap 文件定义站点的层次结构。The Web.sitemap file defines the hierarchical structure of the site. 对于此代码示例,它定义由唯一的 Url (如 1 .aspx、2 .aspx、.aspx 和 .aspx)标识的多个页面,如下所示: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:

网站母版页包含 SiteMapDataSource 控件内的和控件 TreeView ContentPlaceHolderThe Site.master page contains the SiteMapDataSource and a TreeView controls inside a ContentPlaceHolder control. 它使用属性将公开的层次结构的起始节点标识为 default.aspx。 StartingNodeUrlIt identifies the starting node of the exposed hierarchy as Default.aspx, using the StartingNodeUrl property. 仅 default.aspx 页面使用该站点. master 文件。The Site.master file is used by the Default.aspx page only.

所有其他页(如 1 .aspx、2 .aspx、.aspx 等)都使用 "母版页母版页" 部分。All other pages, such as 1.aspx, 2.aspx, A.aspx, and so on, use the Section.master master page. 此母版页非常类似于 Site master,但它包含几个 SiteMapDataSource 可试验的控件。This master page is very similar to Site.master, however it contains several SiteMapDataSource controls that you can experiment with. TreeView显示站点地图数据的控件最初绑定到 SiteMapDataSource1 ,后者指定为 StartingNodeOffset 1。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. 如果你查看第一页,则由显示的层次结构 TreeView 是 A、1、2。If you view page 1.aspx, the hierarchy displayed by the TreeView is A, 1, 2. 但是,如果你查看页 4 .aspx,则层次结构为 B、3、4。However, if you view page 4.aspx, the hierarchy is B, 3, 4.

如果将的更改为 DataSourceID TreeView ,则 SiteMapDataSource2 控件以 TreeView 不同的方式显示站点地图数据。If you change the DataSourceID for the TreeView to SiteMapDataSource2, the TreeView control displays site map data differently. 使用时 SiteMapDataSource2StartFromCurrentNode 属性设置为 true ,这意味着站点地图数据相对于当前请求的页显示,并且 StartingNodeOffset 属性设置为-1,指示在可能的情况下显示一级子节点。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. 查看 .aspx 页时,显示的层次结构是当前级别的层次结构,包括所有同级,如 B 和 C。查看 1 .aspx 时,将不再显示父节点。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.

下面的代码示例演示了可与此代码示例的其他组件一起使用的 ASP.NET 页面之一。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>  

注解

如果 StartingNodeOffset 将属性设置为0以外的值,则它会影响开始节点以及控件公开的站点地图数据层次结构 SiteMapDataSourceIf 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. 的负数或正整数值 StartingNodeOffset 标识由和属性标识的起始节点中的站点图层次结构中的级别数(由和属性标识) StartFromCurrentNodeStartingNodeUrl 以偏移由数据源控件公开的子树的开始节点。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.

如果标识的起始节点是表示当前请求页的节点,则 StartingNodeOffset 将忽略。If the identified starting node is the node that represents the currently requested page, the StartingNodeOffset is ignored.

如果 StartingNodeOffset 将属性设置为负数-n,则由数据源控件公开的子树的开始节点是所标识的起始节点上方的祖先节点 n 层次结构级别。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. 如果值 n 大于层次结构树中的祖先级别数,则该子树的起始节点是站点地图层次结构的根节点。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.

如果将 StartingNodeOffset 属性设置为正数 +n,则公开的子树的起始节点是标识的起始节点下的子节点 n 级别。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. 由于层次结构中可能存在子节点的多个分支,因此在可能的情况下,将 SiteMapDataSource 尝试直接在标识的起始节点与表示当前请求页的节点之间的路径上解析子节点。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. 如果表示当前请求页的节点不在标识的起始节点的子树中,则忽略该属性的值 StartingNodeOffsetIf 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. 如果表示当前请求页的节点小于标识的起始节点下的 n 级,则当前请求的页节点将用作开始节点。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.

属性的值 StartingNodeOffset 存储在视图状态中。The value of the StartingNodeOffset property is stored in view state.

适用于

另请参阅