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

breadcrumbs for treeview

1 Answer 98 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Roukaya
Top achievements
Rank 2
Roukaya asked on 25 Jun 2012, 07:27 AM
Hello  all ,

how can i create a breadcrumbs for RadTreeView (using telerik asp.net ajax) ???

thanks in advance

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Jun 2012, 06:17 AM
Hi Roukaya,

You can achieve this simply by replacing the Menu from the demo with a RadTreeView. Then you will need to change the code behind as follows:
C#:
using System;
using System.Collections.Generic;
using Telerik.Web.UI;
  
namespace Telerik.Web.Examples.Menu.ShowPath
{
    public partial class DefaultCS : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
              
            RadTreeView1.ExpandAllNodes();
  
            RadTreeNode currentNode = RadTreeView1.FindNodeByUrl(Request.Url.PathAndQuery);
            if (currentNode != null)
            {
                //Select the current item and his parents
                HighlightPath(currentNode);
                 
                PageTitleLiteral.Text = currentNode.Text;
                //Populate the breadcrumb
                DataBindBreadCrumbSiteMap(currentNode);
            }
  
        }
  
        public void HighlightPath(RadTreeNode currentNode)
        {
            while (currentNode != null)
            {
                if (!currentNode.CssClass.Contains("focused"))
                {
                    currentNode.CssClass = "focused";
                }
                currentNode = currentNode.Owner as RadTreeNode;
  
            }
  
        }
  
        private void DataBindBreadCrumbSiteMap(RadTreeNode currentNode)
        {
            List<RadTreeNode> breadCrumbPath = new List<RadTreeNode>();
            while (currentNode != null)
            {
                breadCrumbPath.Insert(0, currentNode);
                currentNode = currentNode.Owner as RadTreeNode;
            }
            BreadCrumbSiteMap.DataSource = breadCrumbPath;
            BreadCrumbSiteMap.DataBind();
        }
    }
}
CSS:
.focused
{
 background-color: Yellow !important;
}

Thanks,
Princy.
Tags
TreeView
Asked by
Roukaya
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Share this question
or