Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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()
rptPartnership.DataBind()

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?

TIA.

S

share|improve this question
add comment

1 Answer

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() 
rptPartnership.DataBind()
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
show 2 more comments

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.