Removing child-level checkboxes

9 posts, 1 answers
  1. DonRex
    DonRex avatar
    9 posts
    Member since:
    Dec 2006

    Posted 25 Sep 2008 Link to this post

    Hi all,

    Using the latest trial-version of the ajax-controls, my treeview loads-on-demand from a web service. This works brilliantly and looks shhweeeet! :-)

    The problem is that the child-level inherits the "checkboxes=true" property from the treeview-control and there doesn't seem to be a way turn that off! I need only my top-levels to be checkable - is there any way to obtain this functionality?

    Thanks in advance,

    /Don.
  2. -DJ-
    -DJ- avatar
    263 posts
    Member since:
    Oct 2004

    Posted 25 Sep 2008 Link to this post

    Hi Don,

    One way would be to exchange the = with > in this example:

    http://www.telerik.com/community/forums/thread/b311D-bgdbeg.aspx

    Regards,
    -DJ-
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. DonRex
    DonRex avatar
    9 posts
    Member since:
    Dec 2006

    Posted 25 Sep 2008 Link to this post

    Hi DJ!

    Thanks! Unfortunately neither the NodeCreated or NodeDatabound-event is triggered when the children are loaded from the web service, so that doesn't seem to solve my problem.

    Thanks,

    Don.
  5. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 25 Sep 2008 Link to this post

    Hello DonRex,

    You can handle the OnClientNodeDataBound instead, which fires regardless of the type of data binding. Then in the event handler you can use get_toggleElement() to get a reference to the CheckBox of a Node and remove it from the DOM.

    I hope this helps.

    Best wishes,
    Simon
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. DonRex
    DonRex avatar
    9 posts
    Member since:
    Dec 2006

    Posted 25 Sep 2008 Link to this post

    Simon, that worked like a charm, thank you!

    I'm sure, however, that you meant "get_element()" and not "get_toggleElement()". :-)

    For anyone interested in the solution, here it is:

    TreeView definition:
    <telerik:RadTreeView CheckBoxes="true" OnClientNodeDataBound="ClientNodeDataBound" EnableViewState="true" ID="RadTreeView1" runat="server"/>

    ClientNodeDataBound-event handler

    <script language="javascript" type="text/javascript"
        function ClientNodeDataBound(sender, eventArgs) 
        { 
            var tree = sender; 
            var node = eventArgs.get_node(); 
            var inputs = node.get_element().getElementsByTagName('input'); 
            for (var i = 0; i < inputs.length; i++) 
            { 
                if (inputs[i].getAttribute('type') == 'checkbox'
                    inputs[i].style.display = 'none'
            } 
        } 
    </script>
  7. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 26 Sep 2008 Link to this post

    Hi DonRex,

    get_toggleElement() returns the checkbox. You don't need this code:
     var inputs = node.get_element().getElementsByTagName('input');

    All the best,
    Albert
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  8. DonRex
    DonRex avatar
    9 posts
    Member since:
    Dec 2006

    Posted 26 Sep 2008 Link to this post

    Albert,

    That is strange.

    get_toggleElement() returns 'null' here:

    function ClientNodeDataBound(sender, eventArgs) 
        { 
            var tree = sender; 
            var node = eventArgs.get_node(); 
            var input = node.get_toggleElement(); 
            alert(input); // returns 'null'
        } 

    Do I need to implement it in another way or am I missing something completely?

    eventArgs.get_toggleElement() doesn't work either.

    Thanks in advance,

    /Don.
  9. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 26 Sep 2008 Link to this post

    Hello DonRex,

    Excuse me for misleading you. The proper method is get_checkBoxElement(). get_toggleElement() returns the expand/collapse image which is null for child nodes.
    var node = eventArgs.get_node(); 
    var input = node.get_checkBoxElement(); 

    Greetings,
    Albert
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  10. DonRex
    DonRex avatar
    9 posts
    Member since:
    Dec 2006

    Posted 26 Sep 2008 Link to this post

    Albert,

    Wonderful! That did the trick! I thought I was losing my mind. :-)

    Thanks again,

    /Don.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017