Programmatically set the selected menu item in the Menu control

Last post 01-14-2008 2:52 AM by Amanda Wang - MSFT. 2 replies.

Sort Posts:

  • Programmatically set the selected menu item in the Menu control

    01-11-2008, 9:16 AM
    • Member
      34 point Member
    • scarabee
    • Member since 08-29-2007, 10:24 AM
    • Posts 83

    Is it possible to set the selected menu item in a Menu control programmatically? If so, how? It is possible set the selected menu item in design mode (see code below), but I can't find a way to do the same programmatically.

    <asp:Menu id="mnuLanguage" Orientation="Horizontal" CssClass="tabs" OnMenuItemClick="mnuLanguage_MenuItemClick" Runat="server">
        <Items>
            <asp:MenuItem Text="Tab 1" Value="0" Selected="true" />
            <asp:MenuItem Text="Tab 2" Value="1"  />
            <asp:MenuItem Text="Tab 3" Value="2" />
        </Items>
    </asp:Menu>

     

    Regards, Sigurd 

  • Re: Programmatically set the selected menu item in the Menu control

    01-11-2008, 10:11 AM
    Answer
    • Member
      166 point Member
    • brad75552
    • Member since 08-09-2006, 7:19 PM
    • Posts 37

    Find the menu item and set its selected property to True:

    mnuLanguage.Items(indexToSelect).Selected = True

    I think this removes any other selection, but not sure.

    B

  • Re: Programmatically set the selected menu item in the Menu control

    01-14-2008, 2:52 AM
    Answer

    Hi,

    You can try to set the selected menu item in the Menu controlso Programmatically , like below:

    1.Solution one: 

     MenuItem mi = this.Menu1.FindItem("Home");
     mi.Selected = true;

    2.Solution two:

    this.Menu1.Items[0].Selected = true;

     

    Hope it helps.

    Amanda Wang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (3 items)