I'm creating a web part with some ListView inside.. I tried in many ways to "connect" the javascript SP.ListOperation.Selection.getSelectedItems to my ListView, but it won't work.. With the ListView inserted with the ootb tool no problem, with mine (same base lists) doesn't work!

Here's some code: JS:

<script type"text/javascript">
function GetSelectedDocuments() {
    var clientContext = new SP.ClientContext.get_current();
    this.oWebsite = clientContext.get_web();
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

function onQuerySucceeded() {
    alert('Query OK');
    var items = SP.ListOperation.Selection.getSelectedItems(ctx);
    var myItems = '';
    var k;
    // Loop through items
    for (k in items) {
        myItems += items[k].id + ",";
        alert('ID: ' + items[k].id);
  function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

And the ascx:

        <SharePoint:ListView runat="server" ID="listViewClienti" Visible="false" ListID="{54BA6A4E-917D-427B-B488-60FB41196C38}" View="{15ECCE7F-DD9C-4519-992A-757BDD1E8AB4}"  /> 

The list is well showed, but the SP.ListOperation.Selection cannot get the selected items when invoked.. I tried also with xsltview and other controller...

Do i miss anything to make MY listview equals to the one "sharepoint ootb inserted"?

Thank you very much (sorry for the english but i'm trying to fix this problem from about 15hours!)


I've had to do something similar with a search results page. What I did was actually use JQuery to get the selected items. I made sure that table row the checkboxes were on had a hyperlink to the item, and an attribute on that gave me the ID of the item. My query was:

var selectedItems = new Array();

$('.srch-row:has(input:checkbox:checked)').each(function () {
    id = $(this).find('a').attr('id');
    if ($.inArray(id, selectedItems) < 0) {

Obviously, you could (and probably have) structured your HTML differently, so your query would probably be different, but this sort of technique should work well.


Custom webpart must implenets IWebPartPageComponentProvider interface.


<WebPartPages:XsltListViewWebPart ID="ListViewWebPartPicker" runat="server" ChromeType="None"></WebPartPages:XsltListViewWebPart>


public partial class VisualWebPart1 : WebPart, IWebPartPageComponentProvider
    public WebPartContextualInfo WebPartContextualInfo
            // listViewClienti is 
            return ListViewWebPartPicker.WebPartContextualInfo;

Your Answer

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

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