共用方式為


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

屬性值

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 可用來提供功能表項目文字的自訂格式。 格式字串可以包含常值字串、預留位置或兩者。 常值字串會逐字顯示,而預留位置會取代為系結至功能表項目文字的值。

預留位置分成兩個部分,並以冒號分隔,格式為 { ABxx }。 例如, {0:F2} 顯示具有兩個小數位數的固定點數。

注意

預留位置字串必須以大括弧括住,以指出它是預留位置,而不是常值字串。 大括弧以外的任何文字都會顯示為常值文字。

保留至標準格式字串語法,在一般範例中 (A 冒號前的值,) 在以零起始的參數清單中指定參數索引。 因為每個功能表項目中只能顯示一個值,所以參數索引只能設定為 0。

在一般範例中,冒號之後的字元 (B) 指定值的顯示格式。 下表列出常見的格式。

格式化字元 說明
C 以貨幣格式顯示數值。
D 以十進位格式顯示數值。
E 以科學 (指數) 格式顯示數值。
F 以固定格式顯示數值。
G 以一般格式顯示數值。
N 以數位格式顯示數值。
X 以十六進位格式顯示數值。

注意

格式字元不區分大小寫,但 除外 X ,這會在指定的大小寫中顯示十六進位字元。

在一般範例 (xx 格式字元之後的值,) 會指定要顯示的有效位數或小數位數。

如需格式化字串的詳細資訊,請參閱格式化類型

當設定時,此屬性的值可以使用設計工具自動儲存到資源檔。 如需詳細資訊,請參閱 LocalizableAttribute 和全球化和當地語系化

適用於

另請參閱