Need Help ASAP with Binding Sublevel Items

2 posts, 0 answers
  1. Joshua
    Joshua avatar
    78 posts
    Member since:
    Sep 2008

    Posted 20 Sep 2011 Link to this post

    I'm using RadMenu skin object in DNN.

    For page that are level 3, I want to insert them under their level 2 parent as an undordered, bulleted list. (Please see attachment.)

    How do I accomplish this dynamically?

    I've tried using an itemTemplate, but that doesn't seem to be doing anything.  Perhaps, I'm going about this the wrong way.  Any immediate insight would be appreciated.

    protected void Page_Load(object sender, EventArgs e)
    {
        UnorderedListTemplate template = new UnorderedListTemplate();
        RadMenu menu = dnnMenu.FindControl("RadMenu1") as RadMenu;
        foreach (RadMenuItem item in menu.Items)
            template.InstantiateIn(item);
    }
     
    class UnorderedListTemplate : ITemplate
    {
        public void InstantiateIn(Control container)
        {
            RadSiteMap rsMap = new RadSiteMap();
            rsMap.ID = "radSiteMap";
            rsMap.DataBinding += new EventHandler(MenuItem_DataBinding);
            container.Controls.Add(rsMap);
        }
     
        private void MenuItem_DataBinding(object sender, EventArgs e)
        {
            RadSiteMap target = (RadSiteMap)sender;
            RadMenuItem item = (RadMenuItem)target.BindingContainer;
            target.DataSource = (RadMenuItemCollection)DataBinder.Eval(item, "Items");
        }
    }

  2. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 21 Sep 2011 Link to this post

    Hello Joshua,

    The desired appearance from the attached image resembles RadPanelBar. With RadPanelBar you should use ContentTemplate. Here is a help topic how to add templates dynamically. The Content template requires a little tweak, so here is na example:
    public partial class DynamicContentTemplate : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
        {
            CustomContentTemplate template = new CustomContentTemplate();
            foreach (RadPanelItem item in RadPanelBar1.Items)
            {
                item.ContentTemplate = new CustomContentTemplate();
                template.InstantiateIn(item);
                item.DataBind();
            
        }  
    }
     
    class CustomContentTemplate : ITemplate
    {
        public void InstantiateIn(Control container)
        {
            Label label1 = new Label();
            label1.Font.Bold = true;
            label1.DataBinding += new EventHandler(label1_DataBinding);
            container.Controls.Add(label1);
        }
     
        private void label1_DataBinding(object sender, EventArgs e)
        {
            Label target = (Label)sender;
            RadPanelItem item = (RadPanelItem)target.BindingContainer;
            target.Text = item.Value;
            //Alternative way:
            //string itemText = (string)DataBinder.Eval(item, "Value"); target.Text = itemText;
        }
    }



    Best wishes, Peter
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top