MenuItemBinding.TextField 属性

定义

获取或设置数据源中字段的名称,该字段将绑定到 Text 对象将应用到的 MenuItem 对象的 MenuItemBinding 属性。Gets or sets the name of the field from the data source to bind to the Text property of a MenuItem object to which the MenuItemBinding object is applied.

public:
 property System::String ^ TextField { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string TextField { get; set; }
[System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string TextField { get; set; }
[<System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.TextField : string with get, set
[<System.ComponentModel.TypeConverter("System.Web.UI.Design.DataSourceViewSchemaConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.TextField : string with get, set
Public Property TextField As String

属性值

String

绑定到应用 TextMenuItemMenuItemBinding 的数据源的字段名称。The name of the field from the data source to bind to the Text of a MenuItem to which the MenuItemBinding is applied. 默认值为空字符串 (""),表示尚未设置此属性。The default is an empty string (""), which indicates that this property is not set.

属性

示例

下面的代码示例演示如何使用 TextField 属性指定要绑定到菜单项的属性的字段名称 TextThe following code example demonstrates how to use the TextField property to specify the name of the field to bind to the Text property of a menu item. 要使此示例正常工作,必须将下面的示例 XML 数据复制到名为 Menu.xml 的文件中。For this example to work correctly, you must copy the sample XML data below to a file named 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"
            formatstring="({0})" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_self" />
          <asp:menuitembinding datamember="MapNode" 
            depth="1"
            formatstring="[{0}]" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          <asp:menuitembinding datamember="MapNode" 
            depth="2"
            formatstring="<{0}>" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          
        </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"
            formatstring="({0})" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_self" />
          <asp:menuitembinding datamember="MapNode" 
            depth="1"
            formatstring="[{0}]" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          <asp:menuitembinding datamember="MapNode" 
            depth="2"
            formatstring="<{0}>" 
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"
            target="_blank"/>
          
        </DataBindings>
        
      </asp:menu>

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

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

下面的代码是上一示例的示例站点地图数据。The following code is sample site map data for the previous example.

<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 控件绑定到数据源时,请使用 TextField 属性指定要绑定到对象的属性的字段名称 Text MenuItemWhen the Menu control is bound to a data source, use the TextField property to specify the name of the field to bind to the Text property of a MenuItem object. 呈现时, Text 应用对象的每个菜单项的属性 MenuItemBinding 包含字段中的相应值。When rendered, the Text property of each menu item to which the MenuItemBinding object is applied contains the corresponding value from the field. 此文本显示在菜单项中。This text is displayed in the menu items.

备注

您可以通过直接设置菜单项的属性来覆盖单个菜单项的文本 TextYou can override the text for an individual menu item by setting its Text property directly.

如果数据源包含多个表或属性,则必须先通过设置 Depth 属性和/或属性来建立绑定条件 DataMemberIf the data source contains multiple tables or attributes, you must first establish the binding criteria by setting the Depth property, the DataMember property, or both.

不能 Menu 通过将 TextTextField 属性设置为空字符串 ( "" ) ,在控件中创建空节点。You cannot create empty nodes in a Menu control by setting the Text or TextField properties to the empty string (""). 将这些属性设置为空字符串与不设置属性的效果相同。Setting these properties to the empty string has the same effect as not setting the properties. 在这种情况下, Menu 控件使用属性创建默认绑定 DataSourceIn that case, the Menu control creates a default binding using the DataSource property. 有关详细信息,请参阅ASP.NET 数据访问内容映射For more information, see ASP.NET Data Access Content Map.

Text MenuItem 您还可以通过设置属性将对象的属性绑定到静态值,而不是使用此属性将对象的属性绑定到字段 MenuItemBinding.TextInstead of using this property to bind the Text property of a MenuItem object to a field, you can also bind it to a static value by setting the MenuItemBinding.Text property. 这允许您在应用对象的每个菜单项中显示相同的文本 MenuItemBindingThis allows you to display the same text in each menu item to which the MenuItemBinding object is applied.

备注

如果 Text TextField 同时设置了和属性,则 TextField 属性优先。If the Text and TextField properties are both set, the TextField property takes precedence.

适用于

另请参阅