This is a migrated thread and some comments may be shown as answers.

Binding the Panel bar with IList

8 Answers 80 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Anjali
Top achievements
Rank 1
Anjali asked on 22 Mar 2011, 11:20 PM
Hi All,
  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

Sort by
0
Shivers999
Top achievements
Rank 1
answered on 23 Mar 2011, 04:56 PM
The way I've done it (although I did it for content, not a menu) is to iterate through all the items in your list and add a new RadPanelItem for each - setting the 'Text' and/or 'Value' property of the RadPanelItem. Setting a 'Datasource' and calling 'Databind' was not necessary.
0
Anjali
Top achievements
Rank 1
answered on 23 Mar 2011, 04:58 PM
do you have the sample code for that?
0
Shivers999
Top achievements
Rank 1
answered on 23 Mar 2011, 05:11 PM

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);
            }
                 
        }
0
Anjali
Top achievements
Rank 1
answered on 23 Mar 2011, 07:41 PM
Sorry for the late reply, I am very new to rad controls. In order to use this IContent, do i need to add any namepsace or add any reference. I am developing in visual studio 2010.

Thanks.
0
Accepted
Shivers999
Top achievements
Rank 1
answered on 23 Mar 2011, 08:29 PM
No, I was just showing you this code as an example of how to dynamically build your RadPanelBar. Disregard the IContent and all that. I'm not familiar with 'CSMenuSection' but maybe something like this will work...

*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.
0
Anjali
Top achievements
Rank 1
answered on 23 Mar 2011, 09:11 PM
I don't see radPanelBarParent in my Page_load code. Am I missing an reference? I already added

using

 

 

Telerik.Web.UI;

 

0
Accepted
Shivers999
Top achievements
Rank 1
answered on 23 Mar 2011, 09:16 PM
Sorry, 'RadPanelBarParent' was the ID of the RadPanelBar in the ascx file. I went back and changed it to 'RadPanelBar1'. Change that to match your ascx.
0
Anjali
Top achievements
Rank 1
answered on 23 Mar 2011, 10:51 PM
Thanks Shivers!!
I really appreciate you help.
Tags
PanelBar
Asked by
Anjali
Top achievements
Rank 1
Answers by
Shivers999
Top achievements
Rank 1
Anjali
Top achievements
Rank 1
Share this question
or