Menu with ContextMenu

2 posts, 0 answers
  1. Bob
    Bob avatar
    29 posts
    Member since:
    Jul 2008

    Posted 18 Feb 2009 Link to this post

    Hi Folks,

    I have a contextmenu on my menu.  working fine.

    In the contextMenu *Serverside*  ItemClick event, how do I get to the underlying menu items DataValueField?

    I have my ID col bound to the Menu.  I just need to retrieve it so I can Edit or Delete the underlying data item.
    Thanks,
    Bob
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 Feb 2009 Link to this post

    Hi Bob,

    Try with the following approach and see whether it helps.

    ASPX:
     <telerik:RadMenu ID="RadMenu1" DataSourceID="SqlDataSource1"     DataTextField="ProductName" DataValueField="ProductID" runat="server"
            </telerik:RadMenu> 
     
             <telerik:RadContextMenu  ID="RadContextMenu1"  OnClientShown="OnClientShown"   runat="server" style="left: 1px; top: 157px" OnItemClick="RadContextMenu1_ItemClick"
                <Items > 
                  <telerik:RadMenuItem Text="Edit" ></telerik:RadMenuItem> 
                  <telerik:RadMenuItem Text="Delete" ></telerik:RadMenuItem> 
                </Items> 
             <Targets> 
               <telerik:ContextMenuControlTarget  ControlID="RadMenu1" /> 
             </Targets> 
            </telerik:RadContextMenu> 

    //use a hidden input to store the text of the right clicked menu item
     
     <input type="hidden" id="strText" name="strText" /> 

    JS:
    <script type="text/javascript" > 
    function OnClientShown(menu, args) 
     { 
        var target = args.get_targetElement(); 
         document.getElementById("strText").value = target.innerHTML
          
     } 
    </script> 


    CS:
    protected void RadContextMenu1_ItemClick(object sender, RadMenuEventArgs e) 
        { 
            string strText; 
            strText = Request.Form["strText"]; 
            foreach (RadMenuItem item in RadMenu1.Items) 
            { 
                if (item.Text == strText) 
                { 
                    string strValue = item.Value; 
                } 
            } 
        } 


    Thanks
    Shinu
Back to Top