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

RadListView with ContextMenu

7 Answers 208 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Yu Gene Loh
Top achievements
Rank 1
Yu Gene Loh asked on 12 Nov 2009, 11:20 AM
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

7 Answers, 1 is accepted

Sort by
0
Accepted
Sebastian
Telerik team
answered on 17 Nov 2009, 02:10 PM
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.
0
Yu Gene Loh
Top achievements
Rank 1
answered on 17 Nov 2009, 11:03 PM
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!
0
Steven Amani
Top achievements
Rank 1
answered on 03 Mar 2010, 06:26 PM
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!
0
Sebastian
Telerik team
answered on 04 Mar 2010, 11:44 AM
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.
0
Steven Amani
Top achievements
Rank 1
answered on 11 Mar 2010, 07:32 PM
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>
0
Steven Amani
Top achievements
Rank 1
answered on 11 Mar 2010, 07:58 PM
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.


0
Steven Amani
Top achievements
Rank 1
answered on 11 Mar 2010, 08:17 PM
Solved with (CType(Container, RadListViewDataItem).DisplayIndex%>, event);
Tags
ListView
Asked by
Yu Gene Loh
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Yu Gene Loh
Top achievements
Rank 1
Steven Amani
Top achievements
Rank 1
Share this question
or