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

Menu with ContextMenu

1 Answer 78 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 18 Feb 2009, 07:47 PM
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

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Feb 2009, 11:00 AM
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
Tags
Menu
Asked by
Bob
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or