Share via


MenuItem.Value 屬性

定義

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

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

屬性值

與功能表項目相關的補充資料,但不會顯示。 預設值為空字串 ("")。

範例

下列範例示範如何在使用者選取功能表項目時顯示 Value 功能表項目及其父代的 。


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  
  void NavigationMenu_MenuItemClick(Object sender, MenuEventArgs e)
  {
    // Display the selected menu item.
    if (e.Item.Parent != null)
    {
      Message.Text = "You selected " + e.Item.Value + 
        " from " + e.Item.Parent.Value + ".";
    }
    else
    {
      Message.Text = "You selected " + e.Item.Value + ".";
    }
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItem Value Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItem Value Example</h3>
    
      Select an item from the menu:<br/><br/>
 
      <asp:menu id="NavigationMenu"
        staticdisplaylevels="1"
        staticsubmenuindent="10" 
        orientation="Vertical"
        onmenuitemclick="NavigationMenu_MenuItemClick"  
        runat="server">
        
        <dynamicselectedstyle backcolor="yellow"/>
        <staticselectedstyle backcolor="yellow"/>

        <items>
          <asp:menuitem text="Home"
            tooltip="Home">
            <asp:menuitem text="Category"
              value="Category 1"
              tooltip="Category 1">
              <asp:menuitem text="Topic"
                value="Topic 1"
                tooltip="Topic 1"/>
              <asp:menuitem text="Topic"
                value="Topic 2"
                tooltip="Topic 2"/>
              <asp:menuitem text="Topic"
                value="Topic 3"
                tooltip="Topic 3"/>
            </asp:menuitem>
            <asp:menuitem text="Category"
              value="Category 2"
              tooltip="Category 2">
              <asp:menuitem text="Topic"
                value="Topic 1"
                tooltip="Topic 1"/>
              <asp:menuitem text="Topic"
                value="Topic 2"
                tooltip="Topic 2"/>
              <asp:menuitem text="Topic"
                value="Topic 3"
                tooltip="Topic 3"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>
      
      </asp:menu>

      <hr/>
      
      <asp:label id="Message"
        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">
<script runat="server">
  
  Sub NavigationMenu_MenuItemClick(ByVal sender As Object, ByVal e As MenuEventArgs)
  
    ' Display the selected menu item.
    If e.Item.Parent IsNot Nothing Then
    
      Message.Text = "You selected " & e.Item.Value & _
        " from " & e.Item.Parent.Value & "."
    
    Else
    
      Message.Text = "You selected " & e.Item.Value & "."
      
    End If
      
  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItem Value Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItem Value Example</h3>
    
      Select an item from the menu:<br/><br/>
  
      <asp:menu id="NavigationMenu"
        staticdisplaylevels="1"
        staticsubmenuindent="10" 
        orientation="Vertical"
        onmenuitemclick="NavigationMenu_MenuItemClick"  
        runat="server">
        
        <dynamicselectedstyle backcolor="yellow"/>
        <staticselectedstyle backcolor="yellow"/>

        <items>
          <asp:menuitem text="Home"
            tooltip="Home">
            <asp:menuitem text="Category"
              value="Category 1"
              tooltip="Category 1">
              <asp:menuitem text="Topic"
                value="Topic 1"
                tooltip="Topic 1"/>
              <asp:menuitem text="Topic"
                value="Topic 2"
                tooltip="Topic 2"/>
              <asp:menuitem text="Topic"
                value="Topic 3"
                tooltip="Topic 3"/>
            </asp:menuitem>
            <asp:menuitem text="Category"
              value="Category 2"
              tooltip="Category 2">
              <asp:menuitem text="Topic"
                value="Topic 1"
                tooltip="Topic 1"/>
              <asp:menuitem text="Topic"
                value="Topic 2"
                tooltip="Topic 2"/>
              <asp:menuitem text="Topic"
                value="Topic 3"
                tooltip="Topic 3"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>
      
      </asp:menu>

      <hr/>
      
      <asp:label id="Message"
        runat="server"/>

    </form>
  </body>
</html>

備註

屬性 Value 是用來儲存與功能表項目相關聯的任何其他資料來補充 Text 屬性。 此值不會顯示在 控制項中,而且通常用來儲存資料來處理回傳事件。

注意

Value如果屬性包含 null ,存取子會 get 傳回 屬性的值 TextText如果屬性接著包含 nullEmpty 則會傳回 。

產生 屬性中指定的 ValuePath 值路徑時,也會使用 屬性的值 Value 。 值路徑是分隔符號分隔的功能表項目值清單,可形成從根功能表項目到目前功能表項目的路徑。 值路徑是用來指出控制項中 Menu 功能表項目的位置。

注意

相同功能表層級的功能表項目必須各有屬性的唯一值 Value ; Menu 控制項無法區分相同層級具有相同值的不同功能表項目。

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

適用於

另請參閱