MenuItem.Value Propiedad

Definición

Obtiene o establece un valor que no se muestra en pantalla y que se utiliza para almacenar datos adicionales sobre el elemento de menú, tales como los datos utilizados para controlar los eventos de postback.

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

Valor de propiedad

Datos complementarios, no visibles en pantalla, sobre el elemento de menú. El valor predeterminado es una cadena vacía ("").

Ejemplos

En el ejemplo siguiente se muestra cómo mostrar para Value un elemento de menú y su elemento primario cuando el usuario selecciona un elemento de menú.


<%@ 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>

Comentarios

La Value propiedad se utiliza para complementar la Text propiedad almacenando los datos adicionales asociados al elemento de menú. Este valor no se muestra en el control y se usa normalmente para almacenar datos para controlar eventos de postback.

Nota

Si la Value propiedad contiene null, el get descriptor de acceso devuelve el valor de la Text propiedad . Si la Text propiedad, a su vez, contiene null, Empty se devuelve .

El valor de la Value propiedad también se usa cuando se genera la ruta de acceso de valor especificada en la ValuePath propiedad . Una ruta de acceso de valor es una lista separada por delimitadores de valores de elemento de menú que forman una ruta de acceso del elemento de menú raíz al elemento de menú actual. La ruta de acceso de valor se usa para indicar la posición de un elemento de menú en un Menu control .

Nota

Los elementos de menú del mismo nivel de menú deben tener un valor único para la Value propiedad; el Menu control no puede distinguir entre distintos elementos de menú en el mismo nivel que tienen el mismo valor.

El valor de esta propiedad, cuando se establece, se puede guardar automáticamente en un archivo de recursos mediante una herramienta de diseñador. Para obtener más información, consulte LocalizableAttributeGlobalización y localización.

Se aplica a

Consulte también