MenuItemBinding.Text 属性

定义

获取或设置为应用 MenuItemBinding 对象的菜单项显示的文本。

public:
 property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
public string Text { get; set; }
member this.Text : string with get, set
Public Property Text As String

属性值

String

为应用 MenuItemBinding 的菜单项显示的文本。 默认值为空字符串 (""),表示尚未设置此属性。

示例

下面的代码示例演示如何使用 Text 属性指定要在菜单项中显示的文本。 此文本显示在应用对象的每个菜单项 MenuItemBinding 中。 若要使此示例正常工作,必须将下面的示例 XML 数据复制到名为Menu.xml的文件。


<%@ 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>MenuItemBinding Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemBinding Example</h3>

      <asp:menu id="NavigationMenu"
        datasourceid="MenuSource"
        runat="server">
        
        <databindings>
        
          <asp:menuitembinding datamember="MapHomeNode"
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"/>
          <asp:menuitembinding datamember="MapNode" 
            depth="1"
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"/>
          <asp:menuitembinding datamember="MapNode" 
            depth="2"
            text="Static Title"
            value="Static Description"
            imageurl="~\Images\StaticImage.jpg"
            tooltip="Static ToolTip"/>
          
        </databindings>
        
      </asp:menu>

      <asp:xmldatasource id="MenuSource"
        datafile="Menu.xml"
        runat="server"/> 

    </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">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItemBinding Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemBinding Example</h3>

      <asp:menu id="NavigationMenu"
        datasourceid="MenuSource"
        runat="server">
        
        <databindings>
        
          <asp:menuitembinding datamember="MapHomeNode"
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"/>
          <asp:menuitembinding datamember="MapNode" 
            depth="1"
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"/>
          <asp:menuitembinding datamember="MapNode" 
            depth="2"
            text="Static Title"
            value="Static Description"
            imageurl="~\Images\StaticImage.jpg"
            tooltip="Static ToolTip"/>
          
        </databindings>
        
      </asp:menu>

      <asp:xmldatasource id="MenuSource"
        datafile="Menu.xml"
        runat="server"/> 

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

下面的代码是上一个示例的示例站点地图数据。

<MapHomeNode ImageUrl="~\Images\Home.gif"

Title="Home"

Description="Root Page"

ToolTip="Home Page">

<MapNode ImageUrl="~\Images\Music.gif"

Title="Music"

Description="Music Category"

ToolTip="Music Page">

<MapNode ImageUrl="~\Images\Classical.gif"

Title="Classical"

Description="Classical Section"

ToolTip="Classical Page"/>

<MapNode ImageUrl="~\Images\Rock.gif"

Title="Rock"

Description="Rock Section"

ToolTip="Rock Page"/>

<MapNode ImageUrl="~\Images\Jazz.gif"

Title="Jazz"

Description="Jazz Section"

ToolTip="Jazz Page"/>

</MapNode>

<MapNode ImageUrl="~\Images\Movies.gif"

Title="Movies"

Description="Movies Category"

ToolTip="Movies Page">

<MapNode ImageUrl="~\Images\Action.gif"

Title="Action"

Description="Action Section"

ToolTip="Action Page"/>

<MapNode ImageUrl="~\Images\Drama.gif"

Title="Drama"

Description="Drama Section"

ToolTip="Drama Page"/>

<MapNode ImageUrl="~\Images\Musical.gif"

Title="Musical"

Description="Musical Section"

ToolTip="Musical Page"/>

</MapNode>

</MapHomeNode>

注解

Menu 控件绑定到数据源时,请使用 Text 该属性指定要绑定到 MenuItem.Text 对象的属性 MenuItem 的文本。 此文本显示在菜单项中,并与应用对象的所有菜单项 MenuItemBinding 共享。

备注

可以通过直接设置 Text 其属性来替代单个菜单项的文本。

还可以通过设置TextField属性将对象的属性MenuItem绑定到Text数据源的字段,而不是使用此属性在每个菜单项中显示相同的文本。 呈现时, Text 应用对象的每个菜单项 MenuItemBinding 的属性包含字段中的相应值。

备注

Text如果同时设置和TextField属性,则TextField属性优先。

通过将或TextField属性设置为Text空字符串 (“”) ,无法在控件中创建Menu空节点。 将这些属性设置为空字符串的效果与不设置属性的效果相同。 在这种情况下,该 Menu 控件使用 DataSource 属性创建默认绑定。 有关详细信息,请参阅 ASP.NET 数据访问内容映射

设置时,此属性的值可以使用设计器工具自动保存到资源文件中。 有关详细信息,请参阅LocalizableAttribute全球化和本地化

适用于

另请参阅