Telerik RadMenu仅在鼠标悬停而不在单击时展开

时间:2018-12-20 08:12:34

标签: c# asp.net telerik radmenu

我有一个带有扩展项目菜单的Telerik radmenu。 (请参见下图)

用户可以:

  • 将鼠标悬停在菜单上会显示一个子菜单,然后用户可以单击该子菜单来执行任务。

OR

  • 单击radmenu并执行任务(即保存页面)。这用作快捷方式。

当用户单击或悬停在radmenu上时,将显示子菜单。 但是当用户单击菜单时,我想禁用子菜单。

这意味着用户要么将鼠标悬停在菜单上,然后打开子菜单

OR

单击菜单并执行相关的操作,不会显示任何子菜单。

谢谢您的帮助

enter image description here

这是使用的代码(ascx和ascx.cs):

ascx:

<telerik:RadMenu ID="mnRightMenu" runat="server" Skin="Sapphire" EnableEmbeddedSkins="false" ExpandDelay="700" ClickToOpen="false"
OnClientMouseOut="OnClientMouseOut" OnItemClick="mnQuestion_MenuItemClick"
EnableScreenBoundaryDetection="false" GroupSettings-OffsetY="-10">
    <DefaultGroupSettings ExpandDirection="Left" />
</telerik:RadMenu>

<script type="text/javascript">
    function OnClientMouseOut(sender, args) {
        args.get_item().close();
    }
</script>

ascx.cs:

protected void mnQuestion_MenuItemClick(object sender, RadMenuEventArgs e)
        {
            string a = e.Item.Menu.ItemType.ToString();
            MenuIndex = e.Item.Index + 1;

            if (e.Item.Value.Contains("_item"))
                MenuName = e.Item.Text;
            else
                MenuName = e.Item.Value;

            RadMenuEventHandler handler = MenuSelected;
            if (MenuSelected != null)
                handler(sender, e);
        }

        public void PopulateSubMenu()
        {
            DTO.MarkingVal mv = new DTO.MarkingVal();

            BLL.Right_Menu R = new BLL.Right_Menu();
            DTO.RightMenuList RL = new DTO.RightMenuList();

            BLL.QuestionMenu Q = new BLL.QuestionMenu();
            DTO.QuestionMenuList QL = new DTO.QuestionMenuList();

            BLL.PageMenu P = new BLL.PageMenu();
            DTO.PageMenuList PL = new DTO.PageMenuList();

            mv.OrgID = this.OrgID;
            mv.AssessID = this.AssessID;
            mv.MarkerID = this.MarkerID;
            mv.AppID= this.AppID;
            mv.MAppID = this.MAppID;
            mv.AssessPageNo = this.AssessPageNo;

            RL = R.Select(MenuType);

            QL = Q.Select(mv);

            PL = P.Select(mv);

            this.mnRightMenu.Items.Clear();
            int n= 0;

            foreach(DTO.RightMenu r in RL)
            {
                string fontFormat = "<center class='Name_icon'></center>";
                this.mnRightMenu.Items.Add(new RadMenuItem(r.Text));
                RadMenuItem item = this.mnRightMenu.Items[n];
                item.Value = r.Value;
                item.ToolTip = r.ToolTip;
                item.NavigateUrl = "";
                item.Height=Unit.Pixel(40);

                if (r.IsImage == true)
                    item.ImageUrl = r.ImageURL;

                item.Attributes.Add("IsImage", r.IsImage.ToString());
                item.Attributes.Add("IsFont", r.IsFont.ToString());
                item.Attributes.Add("HasSubMenu", r.HasSubMenu.ToString());
                item.Attributes.Add("onclick",SaveAnnotation);

                if (r.HasSubMenu==true)
                {
                    string menuName=string.Empty;
                    if (item.Value == "Menu")
                    {
                        item.Items.Clear();

                        for (int j = 0; j <= 5; j++)
                        {
                            switch (j)
                            {
                                case 0:
                                    menuName = "Home";
                                    break;
                                case 1:
                                    menuName = "Marking list";
                                    break;
                                case 2:
                                    menuName = "Marking summary";
                                    break;
                                case 3:
                                    menuName = "Save";
                                    break;
                                case 4:
                                    menuName = "Open student's script";
                                    break;
                                case 5:
                                    menuName = "Clear comment bank";
                                    break;
                                default:
                                    menuName = "";
                                    break;
                            }
                            item.Items.Add(new RadMenuItem(menuName));
                            item.Items[j].Value = r.Value + "_item";
                            item.Attributes.Add("IsSubMenu", true.ToString());
                            item.Items[j].Height = Unit.Pixel(25);
                            if (menuName == "Clear comment bank")
                            {
                                string msg = "are you sure you want to clear the bank. All comments (except favorite comments) will be removed from the bank for this question/page";
                                item.Items[j].Attributes.Add("onclick", "javascript: SaveAnnotation; var answer = confirm('" + msg + "'); document.getElementById('" + lblConfirm.ClientID + "').Text = answer;return answer");
                            }
                            else
                                item.Items[j].Attributes.Add("onclick", SaveAnnotation);
                        }
                    }
                    else if (item.Value == "Question")
                    {
                        if (QL.Count > 1)
                        {
                            item.Items.Clear();
                            for (int i = 1; i <= QL.Count + 1; i++)
                            {
                                if (i <= QL.Count)
                                {
                                    DTO.QuestionMenu m = QL.Find((DTO.QuestionMenu QuestionMenu) => QuestionMenu.AssessPageOrder == i);
                                    item.Items.Add(new RadMenuItem(m.QuestionNo.ToString()));
                                    item.Items[i - 1].Value = r.Value + " " + (i).ToString();
                                    if (m.IsFlagged == true)
                                        item.Items[i - 1].ImageUrl = "../../App_Themes/Default/Images/Buttons/btnFlag.png";

                                }
                                else if (i > QL.Count)
                                {
                                    item.Items.Add(new RadMenuItem("General feedback"));
                                    item.Items[i - 1].Value = "Feedback";
                                }
                                item.Attributes.Add("IsSubMenu", true.ToString());
                                item.Items[i - 1].Attributes.Add("onclick", SaveAnnotation);
                                item.Items[i - 1].Height = Unit.Pixel(25);
                            }
                        }
                    }
                    else if (item.Value == "User")
                    {
                        item.Items.Clear();
                        for (int j = 0; j <= 1; j++)
                        {
                            if (j == 0)
                                menuName = "Previous student";
                            else
                                menuName = "Next student";

                            item.Items.Add(new RadMenuItem(menuName));
                            item.Items[j].Value = r.Value + "_item";
                            item.Attributes.Add("IsSubMenu", true.ToString());
                            item.Items[j].Height = Unit.Pixel(25);
                            item.Items[j].Attributes.Add("onclick", SaveAnnotation);
                        }
                    }
                    }
                    n = n + 1;
                }
            }

1 个答案:

答案 0 :(得分:0)

我使用以下代码。菜单将在悬停时展开。用户可以单击菜单项以导航到URL。您可以根据需要进行自定义。

<telerik:RadMenuItem Text="Logs" Value="logs">
    <Items>
        <telerik:RadMenuItem Text="User Session Logs" Value="user_session" NavigateUrl="<URL>">
        </telerik:RadMenuItem>
    </Items>
</telerik:RadMenuItem>