Cascade treeview checkboxeshttp://forums.asp.net/t/1088627.aspx/1?Cascade+treeview+checkboxesThu, 09 Aug 2007 21:47:51 -040010886271626329http://forums.asp.net/p/1088627/1626329.aspx/1?Cascade+treeview+checkboxesCascade treeview checkboxes <p>I'm using microsoft.web.ui.webcontrols.dll.</p> <p>I'm using it for treeview. It very well allows me to populate my tree control on the server side. now i want to make its checbox selection cascading. mean if a parent node is checked to true all the checkboxes of its childnodes should be checked to true and vice versa in case of unchecked. the problem is when i say event.treeNodeIndex in javascript i get the node being clicked by</p> <p>tree.getTreeNode( event.treeNodeIndex ); </p> <p>But how can i check the checkbox within the node. </p> <p>when i see the source rendered for the treeview its just XML nodes. i can't see &lt;input type=&quot;checkbox&quot;/&gt;</p> <p>I want to acheive this using javascript.</p> <p>Please help.&nbsp;</p> 2007-03-19T10:42:55-04:001626346http://forums.asp.net/p/1088627/1626346.aspx/1?Re+Cascade+treeview+checkboxesRe: Cascade treeview checkboxes <p>I'm using ASP.NET 1.1 version. i'm populating it on load event of the page by getting data from SQL Server 2000.</p> <p>thanks.&nbsp;</p> 2007-03-19T10:55:23-04:001850810http://forums.asp.net/p/1088627/1850810.aspx/1?Re+Cascade+treeview+checkboxesRe: Cascade treeview checkboxes <p>HI Ismail,</p> <p>&nbsp;</p> <p>Though its late. check this it works fine with ASP.NET 1.1</p> <p>&nbsp; function CheckSelect()<br> &nbsp;&nbsp; { &nbsp; //initialize tree<br> &nbsp; var tree = GetTreeHandle();<br> &nbsp; //get checked tree node<br> &nbsp;&nbsp;&nbsp; &nbsp; var treenode = tree.getTreeNode(event.treeNodeIndex);<br> &nbsp; //get index of the parent node whose child node is checked.<br> &nbsp;&nbsp;&nbsp; &nbsp; var index=event.treeNodeIndex.charAt(0);<br> &nbsp; //get &quot;type&quot; of the node .Type returns the name of the nodegroup given while loading the<br> &nbsp;//control. In this exmple it is used as (&quot;groups&quot;&nbsp; as parent nodes) and (&quot;contacts&quot; as child nodes)<br> &nbsp; var type=treenode.getAttribute('type');<br> &nbsp; //check whether it is Checked or Unchecked.It returns true or false.<br> &nbsp; var sel=treenode.getAttribute('checked');<br> &nbsp; var i;<br> &nbsp;&nbsp; &nbsp; if (type==&quot;groups&quot;)&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp; &nbsp;{&nbsp;&nbsp;//As the treenode checked is a parent, get the children of that node<br> &nbsp;&nbsp; var objarr= treenode.getChildren();<br> &nbsp;&nbsp;if (sel==true)<br> &nbsp;&nbsp;{//if the parent node is checked then uncheck all child nodes<br> &nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp; for (i=0;i&lt;objarr.length;i&#43;&#43;)<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;objarr[i].setAttribute(&quot;checked&quot;,true);<br> &nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp; }<br> &nbsp;&nbsp;else<br> &nbsp;&nbsp;{//if the parent node is unchecked then uncheck all child nodes<br> &nbsp;&nbsp;<br> &nbsp;&nbsp;&nbsp; for (i=0;i&lt;objarr.length;i&#43;&#43;)<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;objarr[i].setAttribute(&quot;checked&quot;,false);<br> &nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp; }<br> &nbsp;&nbsp;<br> &nbsp;&nbsp; &nbsp;}<br> &nbsp;//if type is not parent node but its a child node then.<br> &nbsp;else<br> &nbsp;{&nbsp;//get parent node of th child node which is Checked<br> &nbsp;&nbsp;var parentnode=tree.getTreeNode(index);<br> &nbsp;&nbsp;//get the children of the parent node<br> &nbsp;&nbsp;var objarr= parentnode.getChildren();<br> &nbsp;&nbsp;var truecheck,falsecheck;<br> &nbsp;&nbsp;truecheck=1;<br> &nbsp;&nbsp;falsecheck=1<br> ;&nbsp;&nbsp;//check All the child nodes are checked or unchecked<br> &nbsp;&nbsp;for (i=0;i&lt;objarr.length;i&#43;&#43;)<br> &nbsp;&nbsp;{<br> &nbsp;&nbsp;&nbsp;if (objarr[i].getAttribute(&quot;checked&quot;)==true)<br> &nbsp;&nbsp;&nbsp;{&nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;falsecheck=0;<br> &nbsp;&nbsp;&nbsp;}<br> &nbsp;&nbsp;&nbsp;else<br> &nbsp;&nbsp;&nbsp;{<br> &nbsp;&nbsp;&nbsp;&nbsp;truecheck=0;<br> &nbsp;&nbsp;&nbsp;}<br> &nbsp;&nbsp;}<br> &nbsp;&nbsp;if (truecheck==1)<br> &nbsp;&nbsp;{//all child nodes are checked so check the parent too...<br> &nbsp;&nbsp;&nbsp;&nbsp;parentnode.setAttribute(&quot;checked&quot;,true);<br> &nbsp;&nbsp;}////&nbsp;&nbsp;<br> &nbsp;&nbsp;else<br> &nbsp;&nbsp;{//none of the child nodes or any of th child node is unchecked<br> &nbsp;&nbsp;//so uncheck the parent node<br> &nbsp;&nbsp;&nbsp;&nbsp;parentnode.setAttribute(&quot;checked&quot;,false);<br> &nbsp;&nbsp;}<br> &nbsp;}<br> &nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp; }//end function</p> <p>function GetTreeHandle()<br> &nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var tree;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var treeName = 'treeview1';//&quot;treeview1&quot; is the id f the TREEVIEW CONTROL USED<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Get a handle to the TreeView.<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tree = document.getElementById( treeName );<br> &nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( null == tree || undefined == tree )<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return null;<br> &nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return tree;<br> &nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; </p> <p>&nbsp;</p> <p>&nbsp;</p> 2007-08-09T21:47:51-04:00