本文介绍了带有子菜单项的asp.net菜单,通过后面的代码重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有2级菜单项的菜单控件!我想通过OnMenuItemClick事件背后的代码进行导航,因为当我使用NavigationUrl属性时,我的ajax UpdateProgress将无法启动!

I have a menu control with 2 levels of menu items!I would like to navigate via code behind OnMenuItemClick event because when i use NavigationUrl property my ajax UpdateProgress wont start!

问题是,无论我单击哪个子菜单项,当事件引发时,它是否每次获得第一个项?!

The Problem is, whatever submenu item i click, when the event raises it gets every time the first item?!

<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时,我将获得Overview menuItem发送到事件?我希望解释是可以理解的? :-)

so when i click Create under HoursOfBusiness i get the Overview menuItem send to the event?!I hope the explanation is understandable?! :-)

推荐答案

这是我解决此问题的方法:

This is how I solved this problem:

<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;

    }
}

希望这将帮助您解决问题.

Hopefully this will help you solve your problem.

这篇关于带有子菜单项的asp.net菜单,通过后面的代码重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 03:59