Bind context menu to a row of .NET repeater

5 posts, 0 answers
  1. bill
    bill avatar
    5 posts
    Member since:
    Oct 2008

    Posted 19 Feb 2014 Link to this post

    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
  2. bill
    bill avatar
    5 posts
    Member since:
    Oct 2008

    Posted 19 Feb 2014 Link to this post

    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);
    }
  3. Plamen
    Admin
    Plamen avatar
    2959 posts

    Posted 24 Feb 2014 Link to this post

    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.
  4. bill
    bill avatar
    5 posts
    Member since:
    Oct 2008

    Posted 03 Mar 2014 in reply to Plamen Link to this post

    Thank-you Plamen and I'm sorry I did not reply earlier. This is similar to the solution that we did use.

    Thanks,
    Bill
  5. Sean
    Sean avatar
    22 posts
    Member since:
    Feb 2018

    Posted 14 Jan Link to this post

    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

Back to Top