Cerebrus

Checkboxes in ASP.NET TreeView

Sep 17th, 2009
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 1.56 KB | None | 0 0
  1. <%--
  2. Related to Questions at:
  3. a) http://groups.google.com/group/dotnetdevelopment/browse_thread/thread/99e294a7d64c4034/
  4. b) http://groups.google.com/group/dotnetdevelopment/browse_thread/thread/6e502f3c0e182093
  5. --%>
  6.  
  7. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
  8.  
  9. <html xmlns="http://www.w3.org/1999/xhtml">
  10. <head runat="server">
  11.   <title>Untitled Page</title>
  12.   <script type="text/javascript" language="javascript">
  13.     function ToggleCheckBoxes(check)
  14.     {
  15.       var tvID = "<%= TreeView1.ClientID %>".concat("n0Nodes");
  16.       var tvNodes = document.getElementById(tvID);
  17.       var chkBoxes = tvNodes.getElementsByTagName("input");
  18.       for (var i = 0; i < chkBoxes.length; i++)
  19.       {
  20.         var chk = chkBoxes[i];
  21.         if (chk.type == "checkbox")
  22.         {
  23.           chk.checked = check;
  24.         }
  25.       }
  26.     }
  27.   </script>
  28. </head>
  29. <body>
  30.   <form id="form1" runat="server">
  31.     <asp:TreeView ID="TreeView1" ShowCheckBoxes="Leaf" runat="server">
  32.       <Nodes>
  33.         <asp:TreeNode Text="Parent1" Expanded="true">
  34.           <asp:TreeNode Text="Child1" Checked="true">
  35.             <asp:TreeNode Text="Child2" Checked="true" />
  36.           </asp:TreeNode>
  37.           <asp:TreeNode Text="Child3" />
  38.           <asp:TreeNode Text="Child4" />
  39.         </asp:TreeNode>
  40.       </Nodes>
  41.     </asp:TreeView>
  42.     <a href="javascript:void(0)" onclick="ToggleCheckBoxes(true);">Check all</a>
  43.     <br />
  44.     <a href="javascript:void(0)" onclick="ToggleCheckBoxes(false);">Uncheck all</a>
  45.   </form>
  46. </body>
  47. </html>
Advertisement
Add Comment
Please, Sign In to add comment