开发者

ASP:Menu.SelectedValue not working

I've been trying to use ASP:Menu.SelectedValue property but it is not working so if anyone has used this before please read on. Here is the code.

<asp:Menu ID="Menu1" runat="server" BackColor="#B5C7DE" 
            DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="0.8em" 
            ForeColor="#284E98" onmenuitemclick="Menu1_MenuItemClick1" 
            StaticSubMenuIndent="10px" Visible="False">
            <DynamicHoverStyle BackColor="#284E98" ForeColor="White" />
            <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
            <DynamicMenuStyl开发者_StackOverflow社区e BackColor="#B5C7DE" />
            <DynamicSelectedStyle BackColor="#507CD1" />
            <Items>
                <asp:MenuItem Selectable="False" Text="Analysis" Value="Analysis">
                    <asp:MenuItem Selectable="False" Text="Descriptive" Value="Descriptive">
                        <asp:MenuItem Text="Mean" Value="Mean"></asp:MenuItem>
                        <asp:MenuItem Text="Median" Value="Median"></asp:MenuItem>
                        <asp:MenuItem Text="Mode" Value="Mode"></asp:MenuItem>
                    </asp:MenuItem>
                </asp:MenuItem>
            </Items>
            <StaticHoverStyle BackColor="#284E98" ForeColor="White" />
            <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
            <StaticSelectedStyle BackColor="#507CD1" />
</asp:Menu>

And the code behind

protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
        {
            MenuItem selectedItem = Menu1.SelectedItem;
            lblUpload.Text = Menu1.SelectedItem.Text;

            if (Menu1.SelectedItem.Text == "Mean")
            {
                lblSet.Visible = true;
                DropDownList1.Visible = true;
                btnCalculate.Visible = true;
            }
        }

I added in the Line

 lblUpload.Text = Menu1.SelectedItem.Text;

to test the output on a visible and working label but nothing is returning. Can anyone see the problem with this? I have also tested;

lblUpload.Text = SelectedItem.Text/.value;
lblUpload.Text = Menu1.SelectedItem.Value;
lblUpload.Text = Menu1.SelectedItem.ValuePath;

None of these affect the label in anyway. Is there problems with this control in general or am I missing an obvious mistake. Appreciate any feedback thanks.


This works as soon as you make Menu1 visible and change onmenuitemclick="Menu1_MenuItemClick1" to onmenuitemclick="Menu1_MenuItemClick".

I Menu1 needs to change visibility please provide the code that shows how you do it.

Edited:

Try to break down the problem into small pieces:

  1. The problem might be that you have an error trying to access the selected menu item
  2. You might have a problem displaying the selected item in lblUpload

The best way check is to set a breakpoint at Menu1_MenuItemClick, start debugging by hitting F5 and have a look at Menu1.SelectedItem.Text there.


Try

lblUpload.Text = e.Item.Text;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜