MenuItemBinding.Text 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定該物件所應用選單項目 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 單一選單項目的屬性來覆蓋該文字。
你也可以透過設定TextField該屬性,將物件的屬性MenuItem綁定Text到資料來源的欄位,而不是用這個屬性在每個選單項目中顯示相同文字。 渲染時, Text 每個套 MenuItemBinding 用該物件的選單項目屬性都會包含該欄位對應的值。
你無法透過將 or TextField 屬性設定Text為空字串(“”)來建立控制Menu節點。 將這些屬性設為空字串,效果與未設定屬性相同。 在這種情況下,控制 Menu 項會根據該 DataSource 屬性建立預設綁定。 欲了解更多資訊,請參閱 資料存取內容地圖 ASP.NET。
設定後,該屬性的值可透過設計工具自動儲存到資源檔案中。 欲了解更多資訊,請參閱LocalizableAttribute全球化與在地化。