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则返回 。

Value生成属性中指定的ValuePath值路径时,也会使用 属性的值。 值路径是菜单项值的分隔符分隔列表,这些值构成从根菜单项到当前菜单项的路径。 值路径用于指示菜单项在控件中 Menu 的位置。

备注

同一菜单级别的菜单项必须具有属性的唯一值 Value ; Menu 控件无法区分同一级别具有相同值的不同菜单项。

设置此属性的值时,可以使用设计器工具自动保存到资源文件。 有关详细信息,请参阅 LocalizableAttribute全球化和本地化

适用于

另请参阅