More in this section

Forums / Developing with Sitefinity / Getting content from list items in a list

Getting content from list items in a list

3 posts, 1 answered
  1. kiran
    kiran avatar
    43 posts
    Registered:
    17 Nov 2010
    07 Nov 2011
    Link to this post

    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.

  2. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    07 Nov 2011
    Link to this post
    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).
    Answered
  3. kiran
    kiran avatar
    43 posts
    Registered:
    17 Nov 2010
    08 Nov 2011
    Link to this post
    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.
3 posts, 1 answered