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

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?



share|improve this question
up vote 1 down vote accepted

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() 
share|improve this answer
thanks Per, get an error on build now...Error 2 'GetItems' is not a member of 'Microsoft.SharePoint.SPListItemCollection' – Stephen Oct 9 '12 at 12:05
Sorry sample changed it's directly on the list – Per Jakobsen Oct 9 '12 at 12:08
Many thanks Per, much appreciated. – Stephen Oct 9 '12 at 12:16
Out of interest can I do an "Order by" on that CAML query? – Stephen Oct 9 '12 at 12:17
Yes you can prefix <Where>... with <OrderBy> <FieldRef Name="Field1" /> <FieldRef Name="Field2" Ascending="FALSE"/> </OrderBy> – Per Jakobsen Oct 9 '12 at 12:37

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.