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'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() {
    alert('INIZIO');
    var clientContext = new SP.ClientContext.get_current();
    this.oWebsite = clientContext.get_web();
    clientContext.load(oWebsite);
    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());
  }
  </script>
  <br/>

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!)

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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(selectedItems, id) == false) {
        selectedItems.push(id);
    }       
});

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

share|improve this answer

Custom webpart must implenets IWebPartPageComponentProvider interface.

ascx:

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

code:

public partial class VisualWebPart1 : WebPart, IWebPartPageComponentProvider
{
    ...
    public WebPartContextualInfo WebPartContextualInfo
    {
        get
        {
            // listViewClienti is 
            return ListViewWebPartPicker.WebPartContextualInfo;
        }
    }
}
share|improve this answer

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.