Solved

How to get ASP.Net TreeView Child Node Value

Posted on 2014-01-08
2
2,223 Views
Last Modified: 2014-01-19
Hi, Expert

I need to get selected child node value from TreeView Control through JavaScript
0
Comment
Question by:Asrar Azmi
2 Comments
 
LVL 4

Accepted Solution

by:
ravikantninave earned 500 total points
Comment Utility
Treeview declaration
    <asp:TreeView ID="TreeView1" Runat="server" DataSourceID="XmlDataSource1" onclick="client_OnTreeNodeChecked();" ShowCheckBoxes="all">
    <DataBindings>
    <asp:TreeNodeBinding DataMember="Category" ValueField="ID" TextField="Name"></asp:TreeNodeBinding>
    <asp:TreeNodeBinding DataMember="Description" ValueField="Value" TextField="Value"></asp:TreeNodeBinding>
    </DataBindings>
    </asp:TreeView>

Open in new window


property onclick="client_OnTreeNodeChecked();" event which actually is the JavaScript function which would accomplish this task.
Javascript

    <script language="javascript" type="text/javascript">
    function client_OnTreeNodeChecked()
    {
    var obj = window.event.srcElement;
    var treeNodeFound = false;
    var checkedState;
    if (obj.tagName == "INPUT" && obj.type == "checkbox") {
    var treeNode = obj;
    checkedState = treeNode.checked;
    do
    {
    obj = obj.parentElement;
    } while (obj.tagName != "TABLE")
    var parentTreeLevel = obj.rows[0].cells.length;
    var parentTreeNode = obj.rows[0].cells[0];
    var tables = obj.parentElement.getElementsByTagName("TABLE");
    var numTables = tables.length
    if (numTables >= 1)
    {
    for (i=0; i < numTables; i++)
    {
    if (tables[i] == obj)
    {
    treeNodeFound = true;
    i++;
    if (i == numTables)
    {
    return;
    }
    }
    if (treeNodeFound == true)
    {
    var childTreeLevel = tables[i].rows[0].cells.length;
    if (childTreeLevel > parentTreeLevel)
    {
    var cell = tables[i].rows[0].cells[childTreeLevel - 1];
    var inputs = cell.getElementsByTagName("INPUT");
    inputs[0].checked = checkedState;
    }
    else
    {
    return;
    }
    }
    }
    }
    }
    }
    </script>

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now