共用方式為


MenuItemBinding.Value 屬性

定義

取得或設定非顯示值,這個值是用來儲存與套用 MenuItemBinding 物件之功能表項目相關的任何其他資料,例如,用於處理回傳事件的資料。

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

屬性值

String

有關套用 MenuItemBinding 之功能表項目的補充資料,這個資料並未顯示。 預設值是空字串 (""),表示這個屬性未設定。

範例

下列程式碼範例示範如何使用 Value 屬性來指定與功能表項目相關聯的非顯示值。 這個值用於套用物件的每個功能表項目 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當控制項系結至資料來源時,請使用 Value 屬性來指定值以系結至 MenuItem.Value 物件的 屬性 MenuItem 。 這個值會與套用物件的所有功能表項目 MenuItemBinding 共用。 指定的值不會顯示在功能表項目中,用來儲存套用物件之功能表項目 MenuItemBinding 的任何其他資料,例如用於處理回傳事件的資料。

注意

您可以直接設定其 Value 屬性,以覆寫個別功能表項目的值。

您也可以藉由設定 ValueField 屬性,將 物件的 屬性 MenuItem 系結 Value 至資料來源的欄位,而不是使用這個屬性來指定每個功能表項目的相同值。 轉譯時, Value 套用物件之每個功能表項目 MenuItemBinding 的 屬性都會包含欄位的對應值。

注意

Value如果 同時設定 和 ValueField 屬性,則 ValueField 屬性會優先使用。

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

適用於

另請參閱