Solved

How to get ASP.Net TreeView Child Node Value

Posted on 2014-01-08
2
2,293 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
ravikantninave earned 500 total points
ID: 39792521
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

749 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