Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am having trouble getting the selected items from a ListViewByQuery webpart, using the Client Object Model (JavaScript).

Code (server-side)

<SharePoint:ListViewByQuery runat="server" ID="lvbqMyNews" Enabled="True" DisableSort="False" DisableFilter="False" />

Code (client-side)

var context = SP.ClientContext.get_current();
SP.ListOperation.Selection.getSelectedItems(context);

//returns: [] when anything is selected.

I've tested the same code when going to a normal List in SharePoint, where it gets the selected items perfectly.

Problem

I am not able to get the selected items from the Embedded ListViewByQuery webpart (User control), when I have selected from a ListViewByQuery in a Webpart where I have added the control myself.

If I attempt the same operation on a normal list, then there is no problem getting the list of items. It seems like the Client Object Model is not aware of the ListViewByQuery webpart..

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

I think your syntax for the Client Object Model might not be correct. It should be:

var context = SP.ClientContext.get_current();
SP.ListOperation.Selection.getSelectedItems(context);

It's SP.ClientContext and not SP.Context.

Also, you could try using the XSLTListViewWebPart instead of ListViewByQuery webpart. I have used it successfully before, with the SP.ListOperation namespace.

See the following links:

http://msdn.microsoft.com/en-us/library/ff630941.aspx http://benredl.wordpress.com/2010/11/30/using-the-xsltlistviewwebpart-with-a-custom-query/

share|improve this answer
    
May I ask if why is it possible to do this only on client side why not on the server side with c# code ??? –  Glolita Apr 15 '13 at 15:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.