Click here to Skip to main content
12,552,576 members (57,460 online)
Rate this:
Please Sign up or sign in to vote.
Hi friends,

I am working with ASP.Net 2008, I wanna show the selected node in a text box, without postback.
Please help me.

Thanks Advance..

Adersh Ram
Posted 3-Aug-12 18:58pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Well, I googled for you. Apparently, if your tree view is called, for example, Adersh, then there's a js object called Adersh_Data. This has a selectedNodeID property, which has a value property.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

This is quite easy to get the selected node of treeview.
Try this:
<asp:treeview id="TreeView1" runat="server" xmlns:asp="#unknown">
    <SelectedNodeStyle ForeColor="Black" />
<asp:button id="Button1" runat="server" text="GetSelectedNode" onclientclick="return GetSelectedNode();" xmlns:asp="#unknown" />
protected void Page_Load(object sender, EventArgs e)
    if (!IsPostBack)
        TreeView1.Nodes.Add(new TreeNode("Mango", "Fruit1"));
        TreeView1.Nodes.Add(new TreeNode("Apple", "Fruit2"));
        TreeView1.Nodes.Add(new TreeNode("Pineapple", "Fruit3"));
        TreeView1.Nodes.Add(new TreeNode("Orange", "Fruit4"));
        TreeView1.Nodes.Add(new TreeNode("Grapes", "Fruit5"));
<script type="text/javascript">
function GetSelectedNode() {
    var treeViewData = window["<%=TreeView1.ClientID%>" + "_Data"];
    if (treeViewData.selectedNodeID.value != "") {
        var selectedNode = document.getElementById(treeViewData.selectedNodeID.value);
        var value = selectedNode.href.substring(selectedNode.href.indexOf(",") + 3, selectedNode.href.length - 2);
        var text = selectedNode.innerHTML;
        alert("Text: " + text + "\r\n" + "Value: " + value);
    } else {
        alert("No node selected.")
    return false;
Refer this[^] also.

Adersh Ram 4-Aug-12 1:32am
Thank you so much _Amy. :)
_Amy 4-Aug-12 1:35am
Welcome. :)
Sweetynewb 20-Dec-12 1:22am
Hi Amit,

Can you tell me how to add new node , below selected node?
i mean new node should be child node of selected node.
Please help me out..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.161021.1 | Last Updated 4 Aug 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100