SiteMapPath.NodeTemplate 属性

定义

获取或设置一个控件模板,用于站点导航路径的所有功能节点。

public:
 virtual property System::Web::UI::ITemplate ^ NodeTemplate { System::Web::UI::ITemplate ^ get(); void set(System::Web::UI::ITemplate ^ value); };
[System.ComponentModel.Browsable(false)]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
[System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.SiteMapNodeItem))]
public virtual System.Web.UI.ITemplate NodeTemplate { get; set; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
[<System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.SiteMapNodeItem))>]
member this.NodeTemplate : System.Web.UI.ITemplate with get, set
Public Overridable Property NodeTemplate As ITemplate

属性值

ITemplate

一个 ITemplate 对象,它实现 InstantiateIn(Control) 方法,以呈现导航路径每个节点的自定义内容。

属性

示例

下面的代码示例演示如何 NodeTemplate在指定一个节点时覆盖为所有节点定义的样式,包括根节点和当前节点的特殊样式。

重要

此示例具有一个接受用户输入的文本框,这是一个潜在的安全威胁。 默认情况下,ASP.NET 网页验证用户输入是否不包含脚本或 HTML 元素。 有关详细信息,请参阅脚本侵入概述

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

<script runat="server">
</script>

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

            <!-- The following example demonstrates some of the orders
                 of precedence when applying styles and templates to
                 functional nodes of a SiteMapPath.

                 A NodeStyle, RootNodeStyle, and CurrentNodeStyle are
                 all defined. However, so is a NodeTemplate. The template
                 is applied to all nodes, and the styles ignored. -->

            <asp:SiteMapPath ID="SiteMapPath1" runat="server"
                RenderCurrentNodeAsLink="true"
                NodeStyle-Font-Names="Franklin Gothic Medium"
                NodeStyle-Font-Underline="true"
                NodeStyle-Font-Bold="true"
                RootNodeStyle-Font-Names="Symbol"
                RootNodeStyle-Font-Bold="false"
                CurrentNodeStyle-Font-Names="Verdana"
                CurrentNodeStyle-Font-Size="10pt"
                CurrentNodeStyle-Font-Bold="true"
                CurrentNodeStyle-ForeColor="red"
                CurrentNodeStyle-Font-Underline="false">
                <NODETEMPLATE>
                        <asp:CheckBox id="CheckBox1" runat="server" Checked="true" />
                        <asp:TextBox id="TextBox1" runat="server" Text="Declarative template" />
                </NODETEMPLATE>
            </asp:SiteMapPath>


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

<script runat="server">
</script>

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

            <!-- The following example demonstrates some of the orders
                 of precedence when applying styles and templates to
                 functional nodes of a SiteMapPath.

                 A NodeStyle, RootNodeStyle, and CurrentNodeStyle are
                 all defined. However, so is a NodeTemplate. The template
                 is applied to all nodes, and the styles ignored. -->

            <asp:SiteMapPath ID="SiteMapPath1" runat="server"
                RenderCurrentNodeAsLink="true"
                NodeStyle-Font-Names="Franklin Gothic Medium"
                NodeStyle-Font-Underline="true"
                NodeStyle-Font-Bold="true"
                RootNodeStyle-Font-Names="Symbol"
                RootNodeStyle-Font-Bold="false"
                CurrentNodeStyle-Font-Names="Verdana"
                CurrentNodeStyle-Font-Size="10pt"
                CurrentNodeStyle-Font-Bold="true"
                CurrentNodeStyle-ForeColor="red"
                CurrentNodeStyle-Font-Underline="false">
                <NODETEMPLATE>
                        <asp:CheckBox id="CheckBox1" runat="server" Checked="true" />
                        <asp:TextBox id="TextBox1" runat="server" Text="Declarative template" />
                </NODETEMPLATE>
            </asp:SiteMapPath>


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

注解

NodeTemplateITemplate对象设置为使用Image其他控件,例如Label,用作所有导航路径节点的用户界面元素。

NodeTemplate如果设置了该属性,模板将覆盖显示的导航节点文本和应用于它的任意NodeStyle内容。 对于当前节点和根节点,如果CurrentNodeTemplate设置了或RootNodeTemplate已设置,则这些模板将重写 。NodeTemplate

可以声明性地将NodeTemplate属性设置为任何 Web 服务器控件,ASP.NET 基础结构执行必要的步骤,将 Web 服务器控件包装为对象ITemplate。 但是,Web 服务器控件不实现 ITemplate 接口;因此,以编程方式处理 ITemplate 属性时,必须为任何模板代码编写 ITemplate 包装器。 然后,该 RootNodeTemplate 属性设置为包装器的实例 ITemplate

适用于

另请参阅