2 checkbox in each node

2 posts, 0 answers
  1. bala
    bala avatar
    9 posts
    Member since:
    Jan 2008

    Posted 14 Sep 2009 Link to this post

    I need 2 checkbox for each node in a treeview, so I use nodetemplate. In that once the parent node checked , all the child node should get selected. is there any property to achieve this, or i have to write javascript for this?
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Sep 2009 Link to this post

    Hi Bala,

    If you are using checkboxes for RadTreeView by setting the CheckBoxes=True, then you could set the CheckChildNodes property to True in order to check all the child nodes when parent node is checked. You can achieve same functionality for CheckBoxes placed in NodeTemplate by adding following client side code.

    You could find out both approaches here:
    ASPX:
     
    <telerik:RadTreeView ID="RadTreeView1" runat="server" CheckBoxes="True" CheckChildNodes="True" OnPreRender="RadTreeView1_PreRender" > 
        <Nodes> 
            <telerik:RadTreeNode runat="server" Text="Root RadTreeNode1"
                <Nodes> 
                    <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1"
                    <Nodes>                 
                        <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1.1"></telerik:RadTreeNode> 
                        <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1.2"></telerik:RadTreeNode> 
                    </Nodes> 
                    </telerik:RadTreeNode> 
                    <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 2"
                    </telerik:RadTreeNode> 
                </Nodes> 
            </telerik:RadTreeNode>         
        </Nodes> 
        <NodeTemplate> 
        <asp:CheckBox ID="CheckBox1" runat="server" /> 
        </NodeTemplate> 
    </telerik:RadTreeView> 

    CS:
     
    protected void RadTreeView1_PreRender(object sender, EventArgs e) 
        foreach( RadTreeNode node in RadTreeView1.GetAllNodes()) 
        { 
            CheckBox chk = (CheckBox)node.FindControl("CheckBox1"); 
            chk.Attributes.Add("onclick","check('"+chk.ClientID+"','"+node.Text+"')"); 
        } 

    JavaScript:
     
    <script type="text/javascript"
    function check(chkboxID, text) 
        var radtreeview1 = $find('<%= RadTreeView1.ClientID %>'); 
        var node = radtreeview1.findNodeByText(text); 
        var chk = node.findControl('CheckBox1'); 
        var chkbox = document.getElementById(chkboxID); 
        if(chkbox.checked) 
        { 
            for(var i=0; i< node._getAllItems().length; i++) 
            { 
                n = node._getAllItems()[i]; 
                var ch = document.getElementById(n.get_contentElement().getElementsByTagName('input').item(1).id); 
                ch.checked = true
            } 
        } 
        else 
        { 
            for(var i=0; i< node._getAllItems().length; i++) 
            { 
                n = node._getAllItems()[i]; 
                var ch = document.getElementById(n.get_contentElement().getElementsByTagName('input').item(1).id); 
                ch.checked = false
            } 
        } 
    </script> 

    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top