Sitefinity CMS

Finding List Items Send comments on this topic.
See Also
Developing with Sitefinity > Modules > Modules API > Lists > List Items > Finding List Items

Glossary Item Box

There are several ways to retrieve one or more ListItems. Choose an appropriate function given the particular scenario:

  • GetListItem(Guid id) - Get a specific ListItem by its ID
  • GetListItems(Guid parentId)  - Get all list items belonging to a particular NamedList passing the ID of the list as an argument
  • GetListItems(INamedList parent) - Get the list items belonging to a particular NamedList by passing the actual NamedList object as an argument
  • GetLists() - Get all list items belonging to a NamedList by accessing the Items property of the INamedList object – INamedList.Items

 

Get a specific ListItem by passing its ID to the GetListItem function:

GetListItem(Guid id) Copy Code
// create a new instance of ListManager
Telerik.Lists.ListManager listManager = new Telerik.Lists.ListManager();
// read the second item from the first list
IList allLists = listManager.GetLists();
if (allLists.Count > 0)
{
   
// get reference to the first list
   
Telerik.Lists.INamedList firstList = (Telerik.Lists.INamedList)allLists[0];
   
if (firstList.Items.Count > 2)
   {
     
// get the ID of the second item - this process is actually redundant, but we
     
// are using it here for the purpose of demonstration
     
Guid secondItemId = ((Telerik.Lists.IListItem)firstList.Items[1]).ID;
           
     
// retrieve the ListItem by passing the id to the GetListItem function
     
Telerik.Lists.IListItem secondItem = listManager.GetListItem(secondItemId);
     
// write the headline of the secondItem to see the result
     
Response.Write(secondItem.Headline);
   }
}


 

Get all list items belonging to a particular NamedList by passing the ID of the list as an argument:

GetListItems(Guid parentId) Copy Code
// create a new instance of ListManager
Telerik.Lists.ListManager listManager = new Telerik.Lists.ListManager();
// get all lists, so that we can take the first one
IList allLists = listManager.GetLists();
if (allLists.Count > 0)
{
   
// get reference to the first list
   
Telerik.Lists.INamedList firstList = (Telerik.Lists.INamedList)allLists[0];
   Guid firstListId = firstList.ID;
   
// get all the items belonging to the first list by passing the ID of the
   
// first list to the GetListItems function
   
IList itemsOfTheFirstList = listManager.GetListItems(firstListId);
          
   
// write all the headlines so that we can see the result
   
foreach (Telerik.Lists.IListItem listItem in itemsOfTheFirstList)
       Response.Write(listItem.Headline +
"<br />");
}

 

Get all list items belonging to a particular NamedList by passing the NamedList itself as an argument:

GetListItems(INamedList parent) Copy Code
// create a new instance of ListManager
Telerik.Lists.ListManager listManager = new Telerik.Lists.ListManager();
// get all lists, so that we can take the first one
IList allLists = listManager.GetLists();
if (allLists.Count > 0)
{
   
// get reference to the first list
   
Telerik.Lists.INamedList firstList = (Telerik.Lists.INamedList)allLists[0];
   
// get all the items belonging to the first list by passing the firstList
   
// to the GetListItems function
   
IList itemsOfTheFirstList = listManager.GetListItems(firstList);
   
// write all the headlines so that we can see the result
   
foreach (Telerik.Lists.IListItem listItem in itemsOfTheFirstList)
       Response.Write(listItem.Headline +
"<br />");
}

 

Get all items belonging to a list by accessing the Items property of the NamedList:

GetLists() Copy Code
// create a new instance of ListManager
Telerik.Lists.ListManager listManager = new Telerik.Lists.ListManager();
// get all lists, so that we can take the first one
IList allLists = listManager.GetLists();
if (allLists.Count > 0)
{
   
// get reference to the first list
   
Telerik.Lists.INamedList firstList = (Telerik.Lists.INamedList)allLists[0];
   
// write all the headlines so that we can see the result
   
// notice how we are looping through the Items property of the firstList NamedList
   
foreach (Telerik.Lists.IListItem listItem in firstList.Items)
       Response.Write(listItem.Headline +
"<br />");
}


  

See Also