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

RadTreeView1.SelectedNode Prob

2 Answers 49 Views
This is a migrated thread and some comments may be shown as answers.
Nitin Nitin
Top achievements
Rank 1
Nitin Nitin asked on 09 Apr 2010, 02:39 PM
I'm trying to add nodes to the tree view as given in the example below on a button click.

But I am not able to get the value of RadTreeView1.SelectedNode.
It always returns me NULL

My .aspx page is as below

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
     <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">
                <telerik:AjaxSetting AjaxControlID="AddButton">
                        <telerik:AjaxUpdatedControl ControlID="RadTreeView1" LoadingPanelID="RadAjaxLoadingPanel1" />
        <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" />
     <qsf:ConfiguratorPanel runat="server" ID="ConfigurationPanel1" Title="Available actions" Orientation="Vertical" Expanded="true">
            <ul >
                    <asp:Button  ID="AddButton" runat="server" OnClick="AddButton_Click"></asp:Button>

        <telerik:RadTreeView ID="RadTreeView1" runat="server" Height="280px" Width="300px"  />


and my .cs code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Telerik.Web.UI;

public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
    protected void AddButton_Click(object sender, EventArgs e)
        IRadTreeNodeContainer target = RadTreeView1;
        if (RadTreeView1.SelectedNode != null)                    // Problem :- condition is not getting satisfied even when I select a tree node
            RadTreeView1.SelectedNode.Expanded = true;
            target = RadTreeView1.SelectedNode;
        RadTreeNode addedNode = new RadTreeNode("Course");
        addedNode.Selected = true;


Please advise me !

Thanks !

2 Answers, 1 is accepted

Sort by
Telerik team
answered on 12 Apr 2010, 08:56 AM
Hello Nitin Nitin,

I guess the problem is that in the demo in the tree.xml file we've set the property Selected = "true" to the Fiction node:

<Node Text="Fiction" Selected="True" />

That way you'll have a selected node in advance and the newly added node "Course" will be a child of it. So you'll need to select an node in your .xml file to be able to satisfy the "if (RadTreeView1.SelectedNode != null)" condition.

You may see the full code in the attached .zip file.

Hope this helps.

Veronica Milcheva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Nitin Nitin
Top achievements
Rank 1
answered on 12 Apr 2010, 02:34 PM
Thanks !
Asked by
Nitin Nitin
Top achievements
Rank 1
Answers by
Telerik team
Nitin Nitin
Top achievements
Rank 1
Share this question