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

プロパティ値

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 直接設定します。

このプロパティを使用して各メニュー項目に同じテキストを表示する代わりに、 プロパティを Text 設定することで、オブジェクトの MenuItem プロパティをデータ ソースのフィールドに TextField バインドすることもできます。 レンダリングされると、オブジェクトが Text 適用される MenuItemBinding 各メニュー項目の プロパティに、フィールドの対応する値が含まれます。

注意

Textプロパティと TextField プロパティの両方が設定されている場合は、 TextField プロパティが優先されます。

または TextField プロパティを空のMenu文字列 ("") に設定Textして、コントロールに空のノードを作成することはできません。 これらのプロパティを空の文字列に設定すると、プロパティを設定しない場合と同じ効果があります。 その場合、コントロールは プロパティを Menu 使用して既定のバインドを DataSource 作成します。 詳細については、「 ASP.NET データ アクセス コンテンツ マップ」を参照してください。

このプロパティの値を設定すると、デザイナー ツールを使用してリソース ファイルに自動的に保存できます。 詳細については、グローバリゼーションとローカライズに関するページを参照してくださいLocalizableAttribute

適用対象

こちらもご覧ください