tree带有CheckBox的TReeView        <asp:TreeView ID="TreeView1" runat="server" onclick="javascript:client_OnTreeNodeChecked();"
            NodeIndent="10" ShowCheckBoxes="All" ShowLines="True" 
            onselectednodechanged="TreeView1_SelectedNodeChanged">
 
        </asp:TreeView>
后台已经添加了 tree节点
            TreeView1.Nodes[0].ChildNodes.Add(new TreeNode("0001-1", "000001-1"));
             TreeView1.Nodes[0].ChildNodes.Add(new TreeNode("0001-2", "000001-2"));
            TreeView1.Nodes[1].ChildNodes.Add(new TreeNode("0002-1", "000002-1"));
求如何获取treeview选中的Checkbox的value【js获取最好了,C#也行】可以共享一个带有Checkbox的TreeView操作Demo 感激不尽
mail: 4694[email protected]

解决方案 »

  1.   

    1  选择了父节点,则它的所有子节点都选中
    2  只要有一个子节点选中, 其父节点就选中<script language="javascript" type="text/javascript">
    function HandleCheckbox()                                           
    {                                                                              
        var element = event.srcElement;                                            
        if (element.tagName == "INPUT" && element.type == "checkbox")              
        {                                                                          
            var checkedState = element.checked;                                   
            while (element.tagName != "TABLE") // Get wrapping table               
            {                                                                      
                element = element.parentElement;                                   
            }                                                                            
            var parentElement = element;
                       
            if(checkedState)
            {
             CheckParents(element);
            } 
                                                                                         
            element = element.nextSibling; //element.tagName = DIV 
                                                                                  
            if (element != null) // If no childrens then exit 
            {                                                                                                     
                var childTables = element.getElementsByTagName("TABLE"); 
                
                for (var tableIndex = 0; tableIndex < childTables.length; tableIndex++)
                {                                                                      
                    CheckTable(childTables[tableIndex], checkedState);      
                } 
            }
            if(checkedState == false)
            {
                UnCheckParents(parentElement);
            }            
                                                                
        }                                                                          
    }                                                                              
                                                                                   
    // Uncheck the parents of the given table, Can remove the recurse (redundant) 
    function CheckParents(table)                                      
    {                                                                              
        if (table == null || table.rows[0].cells.length == 2) // This is the root 
        {                                                                          
            return;                                                                
        }                                                                          
        var parentTable = table.parentElement.previousSibling;
        CheckTable(parentTable, true);                                 
        CheckParents(parentTable);                                    
    }  // Check the parents of the given table, Can remove the recurse (redundant) 
    function UnCheckParents(table)                                      
    {       
                                                                         
        if (table == null || table.rows[0].cells.length == 2) // This is the root  
        {                                                                          
            return;                                                                
        }                                                                    
        var parentTable = table.parentElement.previousSibling; 
       
        var checkedCount  =GetCheckedCount(table.parentElement);
        if(checkedCount == 0)
        {
            CheckTable(parentTable, false);
        }                                                 
        UnCheckParents(parentTable);                                    
    }                                                                              
                                                                                   
    // Handle the set of checkbox checked state                                    
    function CheckTable(table, checked) 
        {                                                                              
        var checkboxIndex = table.rows[0].cells.length - 1;   
        var cell = table.rows[0].cells[checkboxIndex];  
        var checkboxes = cell.getElementsByTagName("INPUT"); 
        if (checkboxes.length == 1) 
        {                                                                          
            checkboxes[0].checked = checked; 
        } 
                                                                               
    }  
    //Get checked children count
    function GetCheckedCount(table)
    {
        var checkedCount = 0; 
        var element = table.nextSibling;
        var childTable = table.getElementsByTagName("TABLE");
        
        for(var tableIndex = 0;tableIndex < childTable.length; tableIndex++)
        {
            var childTables = childTable[tableIndex];
            var checkboxIndex = childTables.rows[0].cells.length - 1;    
            var cell = childTables.rows[0].cells[checkboxIndex];  
            var checkboxes = cell.getElementsByTagName("INPUT");
            if (checkboxes.length == 1 && checkboxes[0].checked == true)
            {                                                                          
                 checkedCount++;            
            }      
        }   
        return  checkedCount;   
    }                                                                            
     </script><asp:TreeView ID="TreeViewModules" runat="server" ShowCheckBoxes="All" onclick="HandleCheckbox();" ShowLines="True" ExpandDepth="1" meta:resourcekey="TreeViewModulesResource1"></asp:TreeView>
      

  2.   

    文章来源:http://www.cnblogs.com/andygui/archive/2007/04/17/716305.html
      

  3.   


                <a href="#TreeView1_SkipLink"><img alt="跳过导航链接。" src="/TreeViewEG/WebResource.axd?d=ddIOmTXeG5akg-kFRcBa5Q2&amp;t=633727640620312500" width="0" height="0" style="border-width:0px;" /></a><div id="TreeView1" onclick="javascript:client_OnTreeNodeChecked();">
    <table cellpadding="0" cellspacing="0" style="border-width:0;">
    <tr>
    <td><a id="TreeView1n0" href="javascript:TreeView_ToggleNode(TreeView1_Data,0,TreeView1n0,'r',TreeView1n0Nodes)"><img src="/TreeViewEG/WebResource.axd?d=vZtf6e_8ZiOqQ8eYDi6G1SRc5Cbrbt9oxR5rsLt3PTIrTB-JZ1HpQ5fbGiukixHw0&amp;t=633727640620312500" alt="折叠 0001" style="border-width:0;" /></a></td><td style="white-space:nowrap;"><input type="checkbox" name="TreeView1n0CheckBox" id="TreeView1n0CheckBox" title="0001" /><a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','s000001')" onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t0');" id="TreeView1t0">0001</a></td>
    </tr>
    </table><div id="TreeView1n0Nodes" style="display:block;">
    <table cellpadding="0" cellspacing="0" style="border-width:0;">
    <tr>
    <td><div style="width:10px;height:1px"><img src="/TreeViewEG/WebResource.axd?d=vZtf6e_8ZiOqQ8eYDi6G1QuV2l8Mf9e-aSocvTVA5Yo1&amp;t=633727640620312500" alt="" /></div></td><td><a id="TreeView1n1" href="javascript:TreeView_ToggleNode(TreeView1_Data,1,TreeView1n1,'t',TreeView1n1Nodes)"><img src="/TreeViewEG/WebResource.axd?d=vZtf6e_8ZiOqQ8eYDi6G1UhlQuicDHeOgPbtXTnh-7AGYgPimHK5gqtWa7DiaKDt0&amp;t=633727640620312500" alt="折叠 0001-1" style="border-width:0;" /></a></td><td style="white-space:nowrap;"><input type="checkbox" name="TreeView1n1CheckBox" id="TreeView1n1CheckBox" title="0001-1" /><a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','s000001\\000001-1')" onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t1');" id="TreeView1t1">0001-1</a></td>
    </tr>
    </table><div id="TreeView1n1Nodes" style="display:block;">
    <table cellpadding="0" cellspacing="0" style="border-width:0;">
    <tr>
    <td><div style="width:10px;height:1px"><img src="/TreeViewEG/WebResource.axd?d=vZtf6e_8ZiOqQ8eYDi6G1QuV2l8Mf9e-aSocvTVA5Yo1&amp;t=633727640620312500" alt="" /></div></td><td><div style="width:10px;height:1px"><img src="/TreeViewEG/WebResource.axd?d=vZtf6e_8ZiOqQ8eYDi6G1QuV2l8Mf9e-aSocvTVA5Yo1&amp;t=633727640620312500" alt="" /></div></td><td><img src="/TreeViewEG/WebResource.axd?d=vZtf6e_8ZiOqQ8eYDi6G1fXreMHpveIgPzIp3WV_eKI1&amp;t=633727640620312500" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="TreeView1n2CheckBox" id="TreeView1n2CheckBox" title="0001-1-1" /><a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','s000001\\000001-1\\000001-1-1')" onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t2');" id="TreeView1t2">0001-1-1</a></td>
    </tr>
    </table>
    </div><table cellpadding="0" cellspacing="0" style="border-width:0;">
    <tr>
    <td><div style="width:10px;height:1px"><img src="/TreeViewEG/WebResource.axd?d=vZtf6e_8ZiOqQ8eYDi6G1QuV2l8Mf9e-aSocvTVA5Yo1&amp;t=633727640620312500" alt="" /></div></td><td><img src="/TreeViewEG/WebResource.axd?d=vZtf6e_8ZiOqQ8eYDi6G1fXreMHpveIgPzIp3WV_eKI1&amp;t=633727640620312500" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="TreeView1n3CheckBox" id="TreeView1n3CheckBox" title="0001-2" /><a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','s000001\\000001-2')" onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t3');" id="TreeView1t3">0001-2</a></td>
    </tr>
    </table>
    </div><table cellpadding="0" cellspacing="0" style="border-width:0;">
    <tr>
    <td><a id="TreeView1n4" href="javascript:TreeView_ToggleNode(TreeView1_Data,4,TreeView1n4,'t',TreeView1n4Nodes)"><img src="/TreeViewEG/WebResource.axd?d=vZtf6e_8ZiOqQ8eYDi6G1UhlQuicDHeOgPbtXTnh-7AGYgPimHK5gqtWa7DiaKDt0&amp;t=633727640620312500" alt="折叠 0002" style="border-width:0;" /></a></td><td style="white-space:nowrap;"><input type="checkbox" name="TreeView1n4CheckBox" id="TreeView1n4CheckBox" title="0002" /><a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','s000002')" onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t4');" id="TreeView1t4">0002</a></td>
    </tr>
    </table><div id="TreeView1n4Nodes" style="display:block;">
    <table cellpadding="0" cellspacing="0" style="border-width:0;">
    <tr>
    <td><div style="width:10px;height:1px"><img src="/TreeViewEG/WebResource.axd?d=vZtf6e_8ZiOqQ8eYDi6G1QuV2l8Mf9e-aSocvTVA5Yo1&amp;t=633727640620312500" alt="" /></div></td><td><img src="/TreeViewEG/WebResource.axd?d=vZtf6e_8ZiOqQ8eYDi6G1fXreMHpveIgPzIp3WV_eKI1&amp;t=633727640620312500" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="TreeView1n5CheckBox" id="TreeView1n5CheckBox" title="0002-1" /><a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','s000002\\000002-1')" onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t5');" id="TreeView1t5">0002-1</a></td>
    </tr>
    </table>
    </div><table cellpadding="0" cellspacing="0" style="border-width:0;">
    <tr>
    <td><img src="/TreeViewEG/WebResource.axd?d=vZtf6e_8ZiOqQ8eYDi6G1TdExr888GUgZFTPsKBs4r01&amp;t=633727640620312500" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="TreeView1n6CheckBox" id="TreeView1n6CheckBox" title="0003" /><a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','s000003')" onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t6');" id="TreeView1t6">0003</a></td>
    </tr>
    </table><table cellpadding="0" cellspacing="0" style="border-width:0;">
    <tr>
    <td><img src="/TreeViewEG/WebResource.axd?d=vZtf6e_8ZiOqQ8eYDi6G1fXreMHpveIgPzIp3WV_eKI1&amp;t=633727640620312500" alt="" /></td><td style="white-space:nowrap;"><input type="checkbox" name="TreeView1n7CheckBox" id="TreeView1n7CheckBox" title="0004" /><a class="TreeView1_0" href="javascript:__doPostBack('TreeView1','s000004')" onclick="TreeView_SelectNode(TreeView1_Data, this,'TreeView1t7');" id="TreeView1t7">0004</a></td>
    </tr>
    </table>
    </div><a id="TreeView1_SkipLink"></a>
    这个是TreeView的html代码  搞不懂如何有js可以获取到Value的值
      

  4.   

    带Checkbox的TreeView
    文章地址:http://blog.sina.com.cn/s/blog_4dd7300501008e44.html
    作者:张峰
      

  5.   


    叶子 帮我看看 如何在js里面获取的 选中节点的Value呢????