MenuItemBinding.Text 屬性

定義

取得或設定為套用 MenuItemBinding 物件之功能表項目所顯示的文字。Gets or sets the text displayed for the menu item to which the MenuItemBinding object is applied.

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 之功能表項目所顯示的文字。The text displayed for the menu item to which the MenuItemBinding is applied. 預設為空字串 (""),表示這個屬性未設定。The default is an empty string (""), which indicates that this property is not set.

範例

下列程式碼範例示範如何使用 Text 屬性來指定要顯示在功能表項目中的文字。The following code example demonstrates how to use the Text property to specify the text to display in a menu item. 此文字會顯示在套用物件的每個功能表項目中 MenuItemBindingThis text is displayed in each menu item to which the MenuItemBinding object is applied. 為了讓此範例正確運作,您必須將下列範例 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"
            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>

下列程式碼是上一個範例的範例網站地圖資料。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 至資料來源時,請使用 Text 屬性來指定要系結至 MenuItem.Text 物件之屬性的文字 MenuItemWhen the Menu control is bound to a data source, use the Text property to specify the text to bind to the MenuItem.Text property of a MenuItem object. 此文字會顯示在功能表項目中,並與套用該物件的所有功能表項目共用 MenuItemBindingThis text is displayed in a menu item and is shared with all menu items to which the MenuItemBinding object is applied.

注意

您可以直接設定專案的屬性來覆寫個別功能表項目的文字 TextYou can override the text for an individual menu item by setting its Text property directly.

您也可以設定屬性,將物件的屬性系結 Text MenuItem 至資料來源的欄位,而不是使用此屬性在每個功能表項目中顯示相同的文字 TextFieldInstead of using this property to display the same text in each menu item, you can also bind the Text property of a MenuItem object to a field of a data source by setting the TextField property. 轉譯時,套用 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.

注意

如果 Text TextField 同時設定了和屬性,則 TextField 會優先使用屬性。If the Text and TextField properties are both set, the TextField property takes precedence.

您無法在控制項中建立空的節點, 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.

設定這個屬性的值時,可以使用設計工具,自動儲存到資源檔中。The value of this property, when set, can be saved automatically to a resource file by using a designer tool. 如需詳細資訊,請參閱 LocalizableAttribute全球化和當地語系化For more information, see LocalizableAttribute and Globalization and Localization.

適用於

另請參閱