MenuItemStyleCollection.Add (Método)
Actualización: noviembre 2007
Agrega el objeto MenuItemStyle especificado al final de la colección actual.
Ensamblado: System.Web (en System.Web.dll)
public int Add( MenuItemStyle style )
public function Add( style : MenuItemStyle ) : int
Parámetros
- style
- Tipo: System.Web.UI.WebControls.MenuItemStyle
El objeto MenuItemStyle que se agrega al final de la colección actual.
El método Add permite agregar el objeto MenuItemStyle especificado al final de la colección. Como alternativa, puede insertar un objeto MenuItemStyle en un índice especificado de la colección, utilizando el método Insert.
En el ejemplo de código siguiente se muestra cómo utilizar la clase MenuItemStyleCollection para especificar la configuración de estilo de los elementos de menú de un control Menu según el nivel del elemento. En este ejemplo, se crea la propiedad LevelMenuItemStyles mediante declaración y se quita un objeto MenuItemStyle y se agrega otro al objeto MenuItemStyleCollection.
<%@ 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 Page_Load(Object sender, EventArgs e) { if (!IsPostBack) { // Use the Add and RemoveAt methods to programmatically // remove the third level menu item style and replace // it with a new style, in this case replacing the green background // and yellow text with the blue background and white text. MenuItemStyle newStyle = new MenuItemStyle(); newStyle.BackColor = System.Drawing.Color.Blue; newStyle.ForeColor = System.Drawing.Color.White; // Remove the last of the three menu item styles. Note that // since the collection has a zero-based index, the third // entry has an index value of 2. MainMenuID.LevelMenuItemStyles.RemoveAt(2); MainMenuID.LevelMenuItemStyles.Add(newStyle); } } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>MenuItemStyleCollection Example</title> </head> <body> <form id="form1" runat="server"> <h3>MenuItemStyleCollection Example</h3> <!--Add MenuItemStyle objects to the MenuItemStyleCollection --> <!--using LevelMenuItemStyles. --> <!--Note that each menu item style represents a level in the menu --> <asp:Menu id="MainMenuID" Font-Names= "Arial" ForeColor="Blue" runat="server"> <LevelMenuItemStyles> <asp:MenuItemStyle BackColor="Azure" Font-Italic="true" Font-Names="Arial" ForeColor="Black" /> <asp:MenuItemStyle BackColor="Black" Font-Italic="false" Font-Names="Arial" ForeColor="White" /> <asp:MenuItemStyle BackColor="Green" Font-Italic="true" Font-Names="Arial" ForeColor="Yellow" /> </LevelMenuItemStyles> <items> <asp:menuitem text="Home" tooltip="Home"> <asp:menuitem text="Music" tooltip="Music"> <asp:menuitem text="Classical" tooltip="Classical"/> <asp:menuitem text="Rock" tooltip="Rock"/> <asp:menuitem text="Jazz" tooltip="Jazz"/> </asp:menuitem> <asp:menuitem text="Movies" tooltip="Movies"> <asp:menuitem text="Action" tooltip="Action"/> <asp:menuitem text="Drama" tooltip="Drama"/> <asp:menuitem text="Musical" tooltip="Musical"/> </asp:menuitem> </asp:menuitem> </items> </asp:Menu> </form> </body> </html>
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.