0

how to get the selected SPListItems in the current SPList ? I thought I would find a helping property like this:

SPListItemCollection mySelectedItems = SPContext.Current.List.getSelectedSPListItems();

but this wasn't available, so any idea how to retrieve these items ?

1

Glolita,

I don't know about getting selected items at server-side, however personally I get the selected items in Javascript like this:

 var ctx = SP.ClientContext.get_current();
 var items = SP.ListOperation.Selection.getSelectedItems(ctx);
 var myItems = '';
 var i;

 for (i in items)
 {
     myItems += '|' + items[i].id;
 }

and assign this value to a Hidden Field in Javascript as:

 document.getElementById("<%= HiddenField1.ClientID %>").value = myItems;

and then call server-side code by clicking a hidden button pro grammatically:

 document.getElementById("buttonId").click();

OR Send this as Query String to the page which contains Visual Web Part and access the Query String at Server-side...

a similar question here

Please have a look at this post

  • Great answer, thanks ! one more question please : what is exactely the type of the variable items? is it: string array ? object collection? because I want to retrieve from those items their attached files on the server side – Glolita Oct 24 '12 at 10:42
  • Glolita, in javascript you don't need to worry about the type... when you have all the item Id's concatenated with '|' in a HiddenField, you can then Split the ids and loop through the ids and get specific items! – Arsalan Adam Khatri Oct 24 '12 at 11:16

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.