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

RadTreeView has no Node.Depth property

5 Answers 259 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 21 Jul 2008, 10:45 PM
Hi,
I'm new to Telerik controls, so please excuse me if this is a silly question. I am trying to set up the RadTreeView, but I cannot find a Node.Depth property.

I am populating the treeview on demand but the data comes from different tables in the DB depending on the node depth that is selected using switch. This works fine with the standard Microsoft issue TreeView but not with the Telerik one.

If this feature is not avaiable, is there an alternative way to capture the Node depth.

Thanks in advance

Jon

5 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 22 Jul 2008, 06:48 AM
Hello Jon,

You can use the Level property for this purpose.

Regards,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jon
Top achievements
Rank 1
answered on 22 Jul 2008, 09:25 AM
Hi Albert,

Thanks for your reply, I did find the level property. I'm not having much luck with the TreeView though. I can get the first level to load fine, but it won't expand any further than that. I'm also getting errors in FireFox. I've been trying to use the structure of your Client side populate on demand example on your site, but with my data access structure. Would you mind having a look at my code to see if you can see where I'm going wrong.

Thanks Jon
 
Here's my code:

<

telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>

 

<

telerik:RadTreeView ID="RadTreeView1" runat="server" Height="300px" Width="300px" OnNodeExpand="RadTreeView1_NodeExpand" OnNodeClick="RadTreeView1_NodeClick" >
<CollapseAnimation Duration="100" /><ExpandAnimation Duration="100" /></telerik:RadTreeView>


protected void Page_Load(object sender, EventArgs e)

{
GetSections();
}

 

void GetSections()

{

List<Section> sections = Section.GetSections();

foreach (Section s in sections)

{

RadTreeNode node = new RadTreeNode(s.SectTitle, s.ID.ToString());

node.ExpandMode =

TreeNodeExpandMode.ServerSideCallBack;

RadTreeView1.Nodes.Add(node);

}

}

protected void RadTreeView1_NodeExpand(object sender, RadTreeNodeEventArgs e)

{

if (e.Node.Level == 1)

{

string sectionId = e.Node.ToString();

List<Department> departments = Department.GetDepartments(Int32.Parse(sectionId));

foreach (Department d in departments)

{

RadTreeNode node = new RadTreeNode(d.DeptTitle, d.ID.ToString());

node.ExpandMode =

TreeNodeExpandMode.ServerSideCallBack;

e.Node.Nodes.Add(node);

e.Node.Expanded =

true;

}

}

 

else if (e.Node.Level == 2)

{

string departmentId = e.Node.ToString();

List<Category> category = Category.GetCategories(Int32.Parse(departmentId));

foreach (Category c in category)

{

RadTreeNode node = new RadTreeNode(c.CatTitle, c.ID.ToString());

node.ExpandMode =

TreeNodeExpandMode.ServerSideCallBack;

RadTreeView1.Nodes.Add(node);

e.Node.Expanded =

true;

}

}

else if (e.Node.Level == 3)

{

string categoryId = e.Node.ToString();

List<Article> article = Article.GetArticles(Int32.Parse(categoryId));

foreach (Article a in article)

{

RadTreeNode node = new RadTreeNode(a.Title, a.ID.ToString());

node.ExpandMode =

TreeNodeExpandMode.ServerSideCallBack;

RadTreeView1.Nodes.Add(node);

e.Node.Expanded =

true;

}

}

}

protected void RadTreeView1_NodeClick(object sender, EventArgs e)

{

if (RadTreeView1.SelectedNode == null) return;

if (RadTreeView1.SelectedNode.Level == 1)

{

Response.Redirect(

"~/Admin/AddEditSection.aspx?ID=" +

RadTreeView1.SelectedNode.Value,

false);

}

 

else if (RadTreeView1.SelectedNode.Level == 2)

{

Response.Redirect(

"~/Admin/AddEditDepartment.aspx?ID=" +

RadTreeView1.SelectedNode.Value,

false);

}

 

else if (RadTreeView1.SelectedNode.Level == 3)

{

Response.Redirect(

"~/Admin/AddEditCategory.aspx?ID=" +

RadTreeView1.SelectedNode.Value,

false);

}

 

else if (RadTreeView1.SelectedNode.Level == 4)

{

Response.Redirect(

"~/Admin/AddEditArticle.aspx?ID=" +

RadTreeView1.SelectedNode.Value,

false);

}

}

0
Atanas Korchev
Telerik team
answered on 22 Jul 2008, 11:30 AM
Hi Jon,

You can try checking with the debugger what is going on inside the NodeExpand event handler. You can also try adding root nodes only on initial load:


protected void Page_Load(object sender, EventArgs
e)
{

   if (!Page.IsPostBack)
  {

     GetSections();
   }

}
Regards,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jon
Top achievements
Rank 1
answered on 22 Jul 2008, 10:53 PM
Hi Albert,
I've tried adding the code you suggested but still no good. The debugger is not throwing any problems up either. I've tried adding breakpoints in the code but the NodeExpand event is not being reached. My best guess is the problem is in the client side code as I am getting the "Completed with Errors" yellow triangle at the bottom of the browser in IE.

I'm also getting the following errors in Firefox error console:

Type is not defined:
Type.registerNamespace("Telerik.Web.UI");



Sys is not defined:
Sys.WebForms.PageRequestManager._initialize('ctl00$TreeViewTest1$RadScriptManager1', document.getElementById('aspnetForm'));
Telerik is not defined:
Telerik.Web.UI.RadTreeView._preInitialize("ctl00_TreeViewTest1_RadTreeView1","0");Sys.Application.initialize();

Don't know if that's any help to you, it means nothing to me.


cheers

Jon

0
Atanas Korchev
Telerik team
answered on 23 Jul 2008, 07:20 AM
Hello Jon,

Those JavaScript errors mean that web resources don't work on your PC. Please check this blog post for instructions how to track and solve this problem.

Regards,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
TreeView
Asked by
Jon
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Jon
Top achievements
Rank 1
Share this question
or