Binding the Panel bar with IList

9 posts, 2 answers
  1. Anjali
    Anjali avatar
    101 posts
    Member since:
    Dec 2010

    Posted 22 Mar 2011 Link to this post

    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.

  2. Shivers999
    Shivers999 avatar
    13 posts
    Member since:
    Feb 2010

    Posted 23 Mar 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Anjali
    Anjali avatar
    101 posts
    Member since:
    Dec 2010

    Posted 23 Mar 2011 Link to this post

    do you have the sample code for that?
  5. Shivers999
    Shivers999 avatar
    13 posts
    Member since:
    Feb 2010

    Posted 23 Mar 2011 Link to this post

    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);
                }
                     
            }
  6. Anjali
    Anjali avatar
    101 posts
    Member since:
    Dec 2010

    Posted 23 Mar 2011 Link to this post

    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.
  7. Answer
    Shivers999
    Shivers999 avatar
    13 posts
    Member since:
    Feb 2010

    Posted 23 Mar 2011 Link to this post

    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.
  8. Anjali
    Anjali avatar
    101 posts
    Member since:
    Dec 2010

    Posted 23 Mar 2011 Link to this post

    I don't see radPanelBarParent in my Page_load code. Am I missing an reference? I already added

    using

     

     

    Telerik.Web.UI;

     

  9. Answer
    Shivers999
    Shivers999 avatar
    13 posts
    Member since:
    Feb 2010

    Posted 23 Mar 2011 Link to this post

    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.
  10. Anjali
    Anjali avatar
    101 posts
    Member since:
    Dec 2010

    Posted 23 Mar 2011 Link to this post

    Thanks Shivers!!
    I really appreciate you help.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017