Solved

How to get ASP.Net TreeView Child Node Value

Posted on 2014-01-08
2
2,250 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

920 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

16 Experts available now in Live!

Get 1:1 Help Now