SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ?

share|improve this question


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:


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

share|improve this answer
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 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.