0

我正在以编程方式在表格的一行内创建一棵树。工作正常,但无法获取分配的事件被调用:

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)   
             }
        }

选中子节点的复选框时如何调用事件?

非常感谢。

4

2 回答 2

0

请将 childNodes.SelectAction = TreeNodeSelectAction.None 更改为 childNodes.SelectAction = TreeNodeSelectAction.Select;

于 2014-06-09T07:00:59.940 回答
0

我通过添加事件找到了解决方案,如下所示:

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

然后,在 javascript 中:

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

这里的解决方案:

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

于 2014-06-10T18:29:11.357 回答