The purpose of the NamedList object is to hold list items (of type ListItem). There are three different ways to create list items:
- CreateListItem() - create a List Item with an empty constructor
- CreateListItem(Guid parentId) - create a List Item with a constructor with specified ID
- CreateListItem(INamedList parent) - create a List Item and add it to a specific List
The following examples demonstrate how to create a new list and add three list items to it by taking advantage of Lists module API.
Create a list and add a List Item with an empty constructor:
| CreateListItem() |
Copy Code |
|
// create new instance of ListManager Telerik.Lists.ListManager listManager = new Telerik.Lists.ListManager(); // create new NamedList to which we are going to add
ListItems Telerik.Lists.INamedList newList = listManager.CreateList("New
list"); // save the list listManager.SaveList(newList);
// create new ListItem with empty constructor Telerik.Lists.IListItem listItem1 =
listManager.CreateListItem();
listItem1.Headline = "List item 1 - headline";
listItem1.Content = "List item 1 - full content";
listItem1.Ordinal = 0;
listItem1.Parent = newList; // save ListItem listManager.SaveListItem(listItem1);
|
Create a List Item with a constructor with specified ID:
| CreateListItem(Guid parentId) |
Copy Code |
|
// create a new ListItem and pass as an argument in the constructor the ID of the List
// to which this item will belong Telerik.Lists.IListItem listItem2 = listManager.CreateListItem(newList.ID);
listItem2.Headline = "List item 2 - headline";
listItem2.Content = "List item 2 - full content";
listItem2.Ordinal = 1; // save ListItem listManager.SaveListItem(listItem2); // notice that we don't need to set the parent because we have created the
instance
// of the ListItem with ID of the parent passed as an argument
|
Create a List Item and add it to a specific List:
| CreateListItem(INamedList parent) |
Copy Code |
|
// create a new ListItem and pass the NamedList to which item will belong
// as an argument in the constructor Telerik.Lists.IListItem listItem3 = listManager.CreateListItem(newList);
listItem3.Headline = "List item 3 - headline";
listItem3.Content = "List item 3 - full content";
listItem3.Ordinal = 2; // save ListItem listManager.SaveListItem(listItem3); // notice that we don't need to set the parent because we have created the
instance
// of the ListItem with the parent (NamedList) passed as an argument
|
See Also