Getting content from list items in a list

Posted by Community Admin on 04-Aug-2018 19:50

Getting content from list items in a list

All Replies

Posted by Community Admin on 07-Nov-2011 00:00


Hello,

I am trying to programmatically get the content from all the list items present in a list that I created in Sitefinity. I am trying to access the title and content in each of the list items and display it on a page. I am trying to databind the content that I get from the list of RadListView. Could you please suggest me any posts/documentation where I can find more information about getting content from a list and databind it to a RadListView?

I have looked the API and I am having difficulty in getting the content for each of the items in the list. I am using the following code below:

ListsManager manager = ListsManager.GetManager();
            ListItem listitems = manager.GetListItems()
                                .Where(i => i.Parent.Title == "FAQ")
                                .Single();

I have tried to loop through the listitems using foreach, but I am getting the error saying that "foreach statement cannot operate on variables of type 'Telerik.Sitefinity.Lists.Model.ListItem' because 'Telerik.Sitefinity.Lists.Model.ListItem' does not contain a public definition for  'GetEnumerator'"

Could you please suggest me how can I get the content as well as the title from the list items and display it on a page.

thank you.

Posted by Community Admin on 07-Nov-2011 00:00

Part of the problem is that you used a .Single which would return a single ListItem...methods like .Where return IEnumerable so you can loop though the results

Try this (or some variation)

foreach (var item in App.WorkWith().ListItems().Where(x => x.Parent.Title == "FAQ").Publihed().Get())
                string title = item.Title;
                string content = item.Content;
            

(you might need the following Using statements)
using Telerik.Sitefinity;
using Telerik.Sitefinity.Model;

But typing App.WorkWith() should give you everything you need (close to it anyway).

Posted by Community Admin on 08-Nov-2011 00:00

Steve,

Thank you for your post. Yes, that did the trick for me to get all the list items. Now, I am working on binding it to a output template.

Thank you.

This thread is closed