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

RadTreeView1.SelectedNode Prob

2 Answers 64 Views
TreeView
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
Hello,
I'm trying to add nodes to the tree view as given in the example below on a button click.
http://demos.telerik.com/aspnet-ajax/treeview/examples/programming/addremovedisable/defaultvb.aspx

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

My .aspx page is as below
[code]

<%@ 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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
     <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="AddButton">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadTreeView1" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" />
     <qsf:ConfiguratorPanel runat="server" ID="ConfigurationPanel1" Title="Available actions" Orientation="Vertical" Expanded="true">
            <ul >
                <li>
                    <asp:Button  ID="AddButton" runat="server" OnClick="AddButton_Click"></asp:Button>
                </li>
            </ul>
        </qsf:ConfiguratorPanel>

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

    </form>
</body>
</html>


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)
    {
        RadTreeView1.LoadContentFile("~/XMLTreeViewStructure/SuiteTemplate.xml");
    }
    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;
        target.Nodes.Add(addedNode)
 }
     
}


[/code]

Please advise me !

Thanks !
Nitin



2 Answers, 1 is accepted

Sort by
0
Veronica
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.
0
Nitin Nitin
Top achievements
Rank 1
answered on 12 Apr 2010, 02:34 PM
Thanks !
Tags
TreeView
Asked by
Nitin Nitin
Top achievements
Rank 1
Answers by
Veronica
Telerik team
Nitin Nitin
Top achievements
Rank 1
Share this question
or