Hi Cerebrus,
In the line
---
var chBoxes = tvNodes.getElementByTagName("input")
---
I had this error message: object doesn't support this property or
method. =(
On Sep 17, 5:20 am, Cerebrus <[email protected]> wrote:
> Using the same principle I demonstrated in the thread (http://
> groups.google.com/group/dotnetdevelopment/browse_thread/thread/
> 99e294a7d64c4034/), we can study the rendered HTML of a TreeView and
> accordingly select/deselect all checkbox elements in the rendered DOM.
>
> Syntax highlighted version at <http://dotnetdevelopment.pastebin.com/
> f225f061b>
> ---
> <%@ Page Language="VB" AutoEventWireup="false"
> CodeFile="Default.aspx.vb" Inherits="_Default" %>
>
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head runat="server">
> <title>Untitled Page</title>
> <script type="text/javascript" language="javascript">
> function ToggleCheckBoxes(check)
> {
> var tvID = "<%= TreeView1.ClientID %>".concat("n0Nodes");
> var tvNodes = document.getElementById(tvID);
> var chkBoxes = tvNodes.getElementsByTagName("input");
> for (var i = 0; i < chkBoxes.length; i++)
> {
> var chk = chkBoxes[i];
> if (chk.type == "checkbox")
> {
> chk.checked = check;
> }
> }
> }
> </script>
> </head>
> <body>
> <form id="form1" runat="server">
> <asp:TreeView ID="TreeView1" ShowCheckBoxes="Leaf" runat="server">
> <Nodes>
> <asp:TreeNode Text="Parent1" Expanded="true">
> <asp:TreeNode Text="Child1" Checked="true">
> <asp:TreeNode Text="Child2" Checked="true" />
> </asp:TreeNode>
> <asp:TreeNode Text="Child3" />
> <asp:TreeNode Text="Child4" />
> </asp:TreeNode>
> </Nodes>
> </asp:TreeView>
> <a href="javascript:void(0)" onclick="ToggleCheckBoxes
> (true);">Check all</a>
> <br />
> <a href="javascript:void(0)" onclick="ToggleCheckBoxes
> (false);">Uncheck all</a>
> </form>
> </body>
> </html>
> ---
>
> HTH,
> Cerebrus.
>
> On Sep 17, 3:34 am, Ana <[email protected]> wrote:
>
> > Hi,
>
> > I have a TreeView and I'm showing checkboxes only for the leaves. I
> > want to include two LinkButtons in the page where the user can click
> > to select all/none checkboxes. How do I do this is JavaScript? Please,
> > be as detailed as possible, as I'm not very used with JavaScript.
>
> > Thanks a lot,
>
> > Ana