Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to get ASP.Net TreeView Child Node Value

Posted on 2014-01-08
2
Medium Priority
?
2,408 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 1500 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

Industry Leaders: 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

A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

916 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