In have the following code which returns a list and binds it to my repeater.

Dim Partnership As SPList = web.Lists("PartnersMedia")
rptPartnership.DataSource = Partnership.Items.GetDataTable()

This is returning all the items in the list, what I want is a particular item so I have created a view which displays the 1 item. Can i access the view in a similar way to above?



1 Answer 1


Build a CAML query using SPQuery

Then you can use something like the following

Dim Partnership As SPList = web.Lists("PartnersMedia") 
Dim query As New SPQuery()
query.Query = "<Where><Eq><FieldRef Name='Status'/><Value Type='Text'>Completed</Value></Eq></Where>"
rptPartnership.DataSource = Partnership.GetItems(query).GetDataTable() 
  • thanks Per, get an error on build now...Error 2 'GetItems' is not a member of 'Microsoft.SharePoint.SPListItemCollection'
    – Stephen
    Oct 9, 2012 at 12:05
  • Sorry sample changed it's directly on the list Oct 9, 2012 at 12:08
  • Out of interest can I do an "Order by" on that CAML query?
    – Stephen
    Oct 9, 2012 at 12:17
  • Yes you can prefix <Where>... with <OrderBy> <FieldRef Name="Field1" /> <FieldRef Name="Field2" Ascending="FALSE"/> </OrderBy> Oct 9, 2012 at 12:37
  • Hmm can I just check something with you Per? My solution is going up on SharePoint online is SPQuery() allowed for SP online?
    – Stephen
    Oct 9, 2012 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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