RadListView with ContextMenu

8 posts, 1 answers
  1. Yu Gene Loh
    Yu Gene Loh avatar
    2 posts
    Member since:
    Jun 2012

    Posted 12 Nov 2009 Link to this post

    Hi there,

    I am trying to integrate a ContextMenu with a RadListView. However, unlike RadGrid, RadListView does not have the event OnRowContextMenu. The question is then, how do I know which item was the ContextMenu meant to work on?

    Cheers,
    Alvin
  2. Answer
    Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 17 Nov 2009 Link to this post

    Hi Yu Gene Loh,

    For your convenience I prepared a sample project which illustrates how to display context menu for RadListView items. Note that the example will be used as basis for a new demo under the Application Scenarios section of RadListView's online demos (which will go live with Q3 2009 SP1).

    To associate the context menu with the listview instance, intercept the oncontextmenu client event of the listview items wrapper (fieldset in this case), get reference to the context menu object client-side and invoke its show method (passing the browser's event argument as parameter).You also need to save the index of the right-clicked listview item on the client, pass it at a later stage inside the OnClientItemClicked event of the context menu, determine the item chosen by the end user and use the methods from RadListView's client API to perform edit, init insert or delete operation.

    Best regards,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Yu Gene Loh
    Yu Gene Loh avatar
    2 posts
    Member since:
    Jun 2012

    Posted 17 Nov 2009 Link to this post

    Thanks Sebastian. Really appreciate your help on this although I have found my way to get it through over the last few days. I would still take a look of the sample project provided by you nevertheless. Once again, really appreciate your help.

    Cheers!
  5. Steven Amani
    Steven Amani avatar
    10 posts
    Member since:
    Jul 2009

    Posted 03 Mar 2010 Link to this post

    I am trying to get this code to work in the Q3 build of Telerki but cannot. I get a warning that oncontextmenu is not a supported event of the ListView. Help!
  6. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 04 Mar 2010 Link to this post

    Hello Steven,

    There should not be any difference in the exact Q3 version you are using. The example is already part of RadControls for ASP.NET AJAX online demos and you can view it here:

    http://demos.telerik.com/aspnet-ajax/controls/examples/integration/listviewwithcontextmenu/defaultcs.aspx?product=listview

    Greetings,
    Sebastian
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. Steven Amani
    Steven Amani avatar
    10 posts
    Member since:
    Jul 2009

    Posted 11 Mar 2010 Link to this post

    I have this error when trying to get the ContextMenu to appear:

    Compiler Error Message: BC30108: 'RadListViewDataItem' is a type andcannot be used as an expression. The offending code looks like:

     <fieldset style="float: left; width: 220px; height: 60px; border: 0px;" oncontextmenu="ShowContextMenu('<%# ((RadListViewDataItem)(Container)).DisplayIndex %>', event);" >
    </code>
  8. Steven Amani
    Steven Amani avatar
    10 posts
    Member since:
    Jul 2009

    Posted 11 Mar 2010 Link to this post

    Right I am an incher closer. The reason for the error is that its C# and I am using VB. I have changed it to:
    oncontextmenu="ShowContextMenu(<%TryCast(Container, RadListViewDataItem).DisplayIndex%>, event);"
    And I get an error that:
     BC30451: Name 'Container' is not declared.


  9. Steven Amani
    Steven Amani avatar
    10 posts
    Member since:
    Jul 2009

    Posted 11 Mar 2010 Link to this post

    Solved with (CType(Container, RadListViewDataItem).DisplayIndex%>, event);
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017