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();

//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.


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..


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

var context = SP.ClientContext.get_current();

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/

| 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy