Create TreeView with events programmatically

I am creating a tree programmatically inside a row in a table. Works fine, but can not get the assigned event is called:

TreeView arbolCapas = new TreeView();
            arbolCapas.ID = "capas";
            foreach (String capa in servicio.Capas)
            {
                TreeNode childNodes = new TreeNode();
                childNodes.Text = capa;
                childNodes.ShowCheckBox = true;
                childNodes.SelectAction = TreeNodeSelectAction.None;         
                arbolCapas.Nodes.Add(childNodes);                
            }            
            arbolCapas.SelectedNodeChanged +=new EventHandler(arbolCapas_TreeNodeCheckChanged);
            tbC.Controls.Add(arbolCapas);
            tbR.Cells.Add(tbC);

 protected void arbolCapas_TreeNodeCheckChanged(Object sender, EventArgs e)
        {
            TreeView elemento = (TreeView)(((CheckBox)sender).Parent);
             foreach (TreeNode node in elemento.CheckedNodes) 
             {                //if (node.Checked)   
             }
        }

How I can call an event when the checkbox of a child node is checked?

Thanks a lot.

Answers


Kindly change childNodes.SelectAction = TreeNodeSelectAction.None to childNodes.SelectAction = TreeNodeSelectAction.Select;


I found the solution by adding the event as follows:

arbolCapas.Attributes.Add("onclick", "OnCheckBoxCheckChanged(event)");

And then, in javascript:

function OnCheckBoxCheckChanged(evt) {
        alert("check change");
}

Here the solution:

http://geekswithblogs.net/ranganh/archive/2009/01/21/updated-asp.net-treeview-checkboxes-ndash-check-all-ndash-javascript.aspx


Need Your Help

Custom phases for a multi-module maven project

maven-3 multi-module

I am currently working on a multi-module project with the following structure.

Jython 2.5.1: UnicodeDecodeError

python beautifulsoup jython-2.5 html5lib

recently I have been trying to parse data from HTML file using Jython scripts in QF-Test 3.5.4 (note that the supported Python version is only 2.5.1 as per release notes for version 3.5.1. -