This is a migrated thread and some comments may be shown as answers.

Search Menu items

3 Answers 135 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
leaders
Top achievements
Rank 1
leaders asked on 07 Mar 2012, 08:22 PM
Hi there,

I'm using radmenu in my project its is binding with dataset.
I want to add search text box next to Radmenu, if the name of the item entered in the text box is present in the menu, then menu should open and the item should be highlight.

Regards,

Leo

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 08 Mar 2012, 06:06 AM
Hello,

Try the following javascript.
JS:
<script type="text/javascript">
 function OnClientClick()
  {
   var menu = $find("<%= RadMenu1.ClientID %>");
   var textbox = document.getElementById("TextBox1");
   for (i = 0; i < menu.get_allItems().length; i++)
    {
     if (menu.get_allItems()[i].get_text()==textbox.value)
      {
       if (menu.get_allItems()[i].get_level() != 0)
        {
         menu.get_allItems()[i].get_parent().open();
         menu.get_allItems()[i].focus();
        }
      }
    }
  }
 function OnClientItemClosing(sender, args)
  {
   args.set_cancel(true);
  }
</script>

Thanks,
Princy.
0
leaders
Top achievements
Rank 1
answered on 09 Mar 2012, 07:35 AM
Hi Princy,

Firstly, I would like to thank you for your time and consideration on my post.

Your solution has fulfilled my requirement.

I have a question what is the purpose of OnClientitemClosing function, because when I add this function in RadMenu OnClientItemClosing event radmenu doesn't respond, with out this function things are perfect.

Thanks & Regards,

Leo
0
Princy
Top achievements
Rank 2
answered on 20 Mar 2012, 07:53 AM
Hi Leo,

When I add OnClientClick event, then RadMenu closes without showing the focused item. OnClientItemClosing event prevents Radmenu from closing. Following is an example which illustrates that the RadMenu closes only on click.
JS:
<script type="text/javascript">
 k = 0;
 function OnClientClick()
  {
   var menu = $find("<%= RadMenu1.ClientID %>");
   var textbox = document.getElementById("TextBox1");
   for (i = 0; i < menu.get_allItems().length; i++)
    {
     if (menu.get_allItems()[i].get_text()==textbox.value)
      {
       if (menu.get_allItems()[i].get_level() != 0)
        {
         menu.get_allItems()[i].get_parent().open();
         menu.get_allItems()[i].focus();
         k = 1;
        }
      }
    }
  }
 function OnClientItemClosing(sender, args)
  {
   if ((args.get_item().get_isOpen() == true) && (k==1))
    {
     args.set_cancel(true);
     k = 0;
    }
  }
</script>
Let me know if you are not able to get this working. Will be glad to assist.

Thanks,
Princy.
Tags
General Discussions
Asked by
leaders
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
leaders
Top achievements
Rank 1
Share this question
or