How to Iterate throgh list to get all listitems
I have Created a List by name FAQ and i have multiple items in that list.
HOw do i iterate through FAQ list to get title and content of all listitems.
I am unable to use forloop. My code is given below
Telerik.Sitefinity.Lists.Model.List list = App.WorkWith().Lists().Where(l => l.Title == "FAQ").Get().FirstOrDefault();
if (list != null && list.ListItemsCount > 0)
foreach (var item in list)
Here foreach loop is given me error
Hi Sunny,
I'm not sure what error you are getting, but it seems you are trying to loop over a collection of Lists, where you actually first need to get the ListItems.
using
(var manager = ListsManager.GetManager())
var faqListItems = manager.GetListItems().Where(x => x.Parent.Title ==
"FAQ"
&& x.Status == ContentLifecycleStatus.Live);
if
(!faqListItems.Any())
return
;
foreach
(var title
in
faqListItems.Select(listItem => listItem.Title))
So you need to get the ListItems from a List (using the Parent property of a ListItem)
Best regards,
Daniel
Thanks Daniel, But i need same code using Fluent API's
Hi,
Please, review our documentation regarding Lists and List Items. There are samples for querying them using both Fluent and Native API.
Regards,
Nikola Zagorchev
Telerik