MenuItemBinding.FormatString プロパティ

定義

MenuItemBinding オブジェクトが適用されるメニュー項目のテキストの表示形式を指定する文字列を取得または設定します。

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

プロパティ値

MenuItemBinding が適用されるメニュー項目のテキストの表示形式を指定する書式指定文字列。 既定値は空の文字列 ("") です。このプロパティが設定されていないことを示します。

次のコード例では、 プロパティを FormatString 使用して、コントロールのメニュー項目に表示されるテキストの書式を設定する方法を Menu 示します。 この例を正しく機能させるには、以下のサンプル 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"
            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>

次のコードは、前の例のサンプル サイト マップ データです。

<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>

注釈

プロパティは FormatString 、メニュー項目のテキストのカスタム書式を提供するために使用されます。 書式指定文字列は、リテラル文字列、プレースホルダー、またはその両方で構成できます。 リテラル文字列は逐語的に表示され、プレースホルダーはメニュー項目のテキストにバインドされている値に置き換えられます。

プレースホルダーは、コロンで区切られた 2 つの部分に {A:Bxx} という形式で分割されます。 たとえば、 {0:F2} は小数点以下 2 桁の固定小数点番号を表示します。

Note

プレースホルダー文字列は、リテラル文字列ではなくプレースホルダーであることを示すために、中かっこで囲む必要があります。 中かっこの外側のすべてのテキストは、リテラル テキストとして表示されます。

標準の書式設定文字列構文を維持すると、コロンの前の値 (A 一般的な例では) は、パラメーターの 0 から始まるリストでパラメーター インデックスを指定します。 各メニュー項目に表示できる値は 1 つだけなので、パラメーター インデックスは 0 にのみ設定できます。

コロンの後の文字 (B 一般的な例では) は、値の表示形式を指定します。 次の表に、一般的な形式を示します。

文字の書式設定 説明
C 数値を通貨形式で表示します。
D 数値を 10 進形式で表示します。
E 数値を指数 (指数) 形式で表示します。
F 数値を固定形式で表示します。
G 数値を一般的な形式で表示します。
N 数値を数値形式で表示します。
X 数値を 16 進数形式で表示します。

Note

書式文字では、 を除き、大文字と小文字は区別されません。この場合 X、指定した大文字と小文字が区別されます。

書式文字 (xx の一般的な例では) の後の値は、表示する有効桁数または小数点以下の桁数を指定します。

書式指定文字列の詳細については、「Formatting Types」(型の書式設定) を参照してください。

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

適用対象

こちらもご覧ください