I need to bind the panel bar with IList.
I have a class library from where, i am getting the iList. In here DataReview, Score, something else, section 2 and sample are my parent and "", "/Score/Index", "/something/something", "", "/something/something" are my childeren in panel bar. The childrens are the links. How can I bind my panel bar with IList so that I can get the parents and childerens as links.
public IList<CsMenuSection> GetMenuItems()
{
// go to DB to find menu items.
CsMenuSection section = new CsMenuSection("DataReview","");
section.AddMenuItem(
new CsMenuItem("Score ", "/Score/Index"));
section.AddMenuItem(
new CsMenuItem("Something else", "/something/something"));
CisMenuSection section2 = new CsMenuSection("Section 2", "");
section.AddMenuItem(
new CsMenuItem("Sample", "/Scoring/Selectreps"));
_menu_item_list.Add(section);
_menu_item_list.Add(section2);
return MenuItemList;
}
MY CsmenuItem looks lik this
namespace
CSModel
{
public class CsMenuItem
{
private String _text;
private String _link;
public CsMenuItem()
{
}
public CsMenuItem( String text, String link)
{
Text = text;
Link = link;
}
public String Text
{
get { return _text; }
set { _text = value; }
}
public String Link
{
get { return _link; }
set { _link = value; }
}
}
}
Can anyone please help me with this. I really need it urgently.
8 Answers, 1 is accepted
This code taps into the Sitefinity API to get the data for the IList.
// retrieve the content items
IList listOfContentItems = contentManager.GetContent(filter.ToArray());
if
(listOfContentItems.Count > 0)
{
// iterate through the list to add a new RadPanelBar Item for GC Item
foreach
(IContent contentItem
in
listOfContentItems)
{
//Create new bar
RadPanelItem NewItem =
new
RadPanelItem(contentItem.GetMetaData(
"Name"
).ToString());
//Create child content container
RadPanelItem NewChild =
new
RadPanelItem();
//Add the child
NewItem.Items.Add(NewChild);
//Set the 'Value' property of the child
NewChild.Value = contentItem.Content.ToString();
//Add the parent
RadPanelBar1.Items.Add(NewItem);
}
}
Thanks.
*This code is untested:
foreach
(CSMenuSection section
in
GetMenuItems())
{
//Create new bar
RadPanelItem NewItem =
new
RadPanelItem(section.SectionName);
//Add the parent
RadPanelBar1.Items.Add(NewItem);
foreach
(CSMenuItem item
in
section){
//Create new bar
RadPanelItem ChildItem =
new
RadPanelItem(item.ItemName);
RadPanelItem InternalChildItem =
new
RadPanelItem();
//Add to the child
ChildItem.Items.Add(InternalChildItem);
// Set the content
InternalChildItem.Value = item.ItemLink;
//Add to the parent
NewItem.Items.Add(ChildItem);
}
}
Now obviously I don't expect this code to work without some tweeking, but hopefully this will get you to a good place in undestanding how to iterate through your IList.
NOTE: You probably will need to implement an ItemTemplate to get your links to click. I can't really help you with that but I can point you here. This will help you to build a template for your links.
NOTE: This code will only support 2 levels of navigation. If you have a third, you'll need to add another loop or two.
using
Telerik.Web.UI;
I really appreciate you help.