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

Bind context menu to a row of .NET repeater

4 Answers 55 Views
Menu
This is a migrated thread and some comments may be shown as answers.
bill
Top achievements
Rank 1
bill asked on 19 Feb 2014, 05:03 PM
Hi,

I have a context menu that's inside of a .NET repeater and I'm trying to use the menu's show method when a repeater row is clicked on. The menu shows when a row is clicked but I'm having trouble binding the menu to that particular row - clicking on any row of the repeater causes the menu to be bound to the last row in the repeater. I was wondering if there is a way to do this?

The code is basically:

<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="rptSchedules_ItemDataBound">
<ItemTemplate>
<tr data='<%# Eval("ddd") %>' runat="server" id="trItemRow" onclick="javascript: showConMenu(this,event); return false;">
<td>
<%# GetFormattedDateDisplay(Eval("InTime"))%>
</td>
<td>
<%# GetFormattedDateDisplay(Eval("OutTime"))%>
</td>
</tr>
<telerik:RadContextMenu runat="server" ID="ctxRowMenu" OnItemClick="TelerikMenuItemClick"
OnClientItemClicked="Client_MenuClicked" OnClientLoad="conMenuLoad">
<Items>
<telerik:RadMenuItem Text="Add" runat="server" PostBack="true">
</Items>
<Targets>
<telerik:ContextMenuControlTarget ControlID="trItemRow" />
</Targets>
</telerik:RadContextMenu>
</ItemTemplate>
</asp:Repeater>

Thanks,
Bill

4 Answers, 1 is accepted

Sort by
0
bill
Top achievements
Rank 1
answered on 19 Feb 2014, 05:08 PM
Sorry, I didn't include the JS on my original post:

function showConMenu(sender, args) {
var menu = contextMenu;
if ((!e.relatedTarget) || (!$telerik.isDescendantOrSelf(contextMenu.get_element(), e.relatedTarget))) {
menu.show(args); 
$telerik.cancelRawEvent(e);
}
0
Plamen
Telerik team
answered on 24 Feb 2014, 12:15 PM
Hello Bill,

As far as I could understand you are trying to add a RadContextMenu on click of an item of the Repeater. I am attaching my sample web page where similar behavior is implemented.

Hope this will be helpful.

Regards,
Plamen
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
0
bill
Top achievements
Rank 1
answered on 04 Mar 2014, 01:15 AM
Thank-you Plamen and I'm sorry I did not reply earlier. This is similar to the solution that we did use.

Thanks,
Bill
0
Sean
Top achievements
Rank 1
answered on 14 Jan 2019, 03:31 PM

Hello, 

I am having a similar problem and cannot really use your solution. In my case i have div in asp repeater with an ID="xyz" 

then i have a RadContextMenu (doesnt matter if i put this is or out of repeater) and i set the <Targets> <telerik:ContextMenuElementTarget ElementID="xyz" /> </Targets>

everything works great of first div, but 2nd, 3rd and so on its not working. Inside div i have an area which handles onclick to do something else. of that area oncontextmenu i am doing e.PreventDefault() to not show ie11 context menu. Will appreciate any help.

 

Thank you,

Sean

Tags
Menu
Asked by
bill
Top achievements
Rank 1
Answers by
bill
Top achievements
Rank 1
Plamen
Telerik team
Sean
Top achievements
Rank 1
Share this question
or