带有子菜单项的asp.net菜单,后面的代码重定向

时间:2011-10-10 11:06:20

标签: asp.net menuitem

我有一个菜单控件有2级菜单项! 我想通过OnMenuItemClick事件后面的代码导航,因为当我使用NavigationUrl属性时,我的ajax UpdateProgress不会启动!

问题是,无论我点击什么子菜单项,当事件引发时,每次第一项都会得到它?!

<asp:Menu ID="Menu1" runat="server" onmenuitemclick="Menu1_MenuItemClick" >
...
    <Items>
    <asp:MenuItem Text="WorkFlows">
    <asp:MenuItem Text="Overview" Value="Workflow"></asp:MenuItem>
    <asp:MenuItem Text="Edit" Value="Workflow"></asp:MenuItem>
    <asp:MenuItem Text="Create" Value="Workflow"></asp:MenuItem>
    <asp:MenuItem Text="Delete" Value="Workflow"></asp:MenuItem>
    </asp:MenuItem>

    <asp:MenuItem Text="HoursOfBusiness">
    <asp:MenuItem Text="Overview" Value="HoursOfBusiness"></asp:MenuItem>
    <asp:MenuItem Text="Edit" Value="HoursOfBusiness"></asp:MenuItem>
    <asp:MenuItem Text="Create" Value="HoursOfBusiness"></asp:MenuItem>
    <asp:MenuItem Text="Delete" Value="HoursOfBusiness"></asp:MenuItem>
    </asp:MenuItem>


    </Items>
    </asp:Menu>

protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
        {

            switch (e.Item.Value)
            {
                case "Workflow":
                    switch (e.Item.Text)
                    {
                        case "Overview":
                            Response.Redirect("~/RGS/Workflow/Workflow.aspx");
                            break;
                            case "Edit":
                            Response.Redirect("~/RGS/Workflow/WorkflowEdit.aspx");
                            break;
                            case "Create":
                            Response.Redirect("~/RGS/Workflow/WorkflowCreate.aspx");
                            break;
                            case "Delete":
                            Response.Redirect("~/RGS/Workflow/WorkflowDelete.aspx");
                            break;
                    }
                    break;
                case "HoursOfBusiness":
                    switch (e.Item.Text)
                    {
                        case "Overview":
                            Response.Redirect("~/RGS/Workflow/BusinessHour/BusinessHours.aspx");
                            break;
                        case "Edit":
                            Response.Redirect("~/RGS/Workflow/BusinessHour/BusinessHours.aspx");
                            break;
                        case "Create":
                            Response.Redirect("~/RGS/Workflow/BusinessHour/BusinessHoursCreate.aspx");
                            break;
                        case "Delete":
                            Response.Redirect("~/RGS/Workflow/BusinessHour/BusinessHours.aspx");
                            break;
                    }
                    break;
            }

所以当我点击HoursOfBusiness下的Create时,我会得到概述menuItem发送给活动?! 我希望解释是可以理解的?! : - )

1 个答案:

答案 0 :(得分:6)

这就是我解决这个问题的方法:

<asp:Menu ID="Menu1" runat="server" OnMenuItemClick="Menu1_MenuItemClick">
    <Items>
        <asp:MenuItem Text="WorkFlows">
            <asp:MenuItem Text="Overview" />
            <asp:MenuItem Text="Edit" />
            <asp:MenuItem Text="Create" />
            <asp:MenuItem Text="Delete" />
        </asp:MenuItem>
        <asp:MenuItem Text="HoursOfBusiness">
            <asp:MenuItem Text="Overview" />
            <asp:MenuItem Text="Edit" />
            <asp:MenuItem Text="Create" />
            <asp:MenuItem Text="Delete" />
        </asp:MenuItem>
    </Items>
</asp:Menu>

背后的代码是这样的:

protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
{
    bool hasParent = (e.Item.Parent != null);

    switch (hasParent)
    {
        case false:
            switch (e.Item.Value)
            {
                case "WorkFlows":
                    Response.Redirect("~/RGS/Workflow/Workflow.aspx");
                    break;
                case "HoursOfBusiness":
                    Response.Redirect("~/RGS/Workflow/BusinessHour/BusinessHours.aspx");
                    break;
            }
            break;
        case true:
            switch (e.Item.Parent.Value)
            {
                case "WorkFlows":
                    switch (e.Item.Value)
                    {
                        case "Overview":
                            Response.Redirect("~/RGS/Workflow/Workflow.aspx");
                            break;
                        case "Edit":
                            Response.Redirect("~/RGS/Workflow/WorkflowEdit.aspx");
                            break;
                        case "Create":
                            Response.Redirect("~/RGS/Workflow/WorkflowCreate.aspx");
                            break;
                        case "Delete":
                            Response.Redirect("~/RGS/Workflow/WorkflowDelete.aspx");
                            break;
                    }
                    break;
                case "HoursOfBusiness":
                    switch (e.Item.Value)
                    {
                        case "Overview":
                            Response.Redirect("~/RGS/Workflow/BusinessHour/BusinessHours.aspx");
                            break;
                        case "Edit":
                            Response.Redirect("~/RGS/Workflow/BusinessHour/BusinessHours.aspx");
                            break;
                        case "Create":
                            Response.Redirect("~/RGS/Workflow/BusinessHour/BusinessHoursCreate.aspx");
                            break;
                        case "Delete":
                            Response.Redirect("~/RGS/Workflow/BusinessHour/BusinessHours.aspx");
                            break;
                    }
                    break;
            }
            break;

    }
}

希望这可以帮助您解决问题。