Disable all parent nodes

5 posts, 0 answers
  1. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 09 Dec 2008 Link to this post

    Hi

    I've a tree view bound to a database, this is my code, and it works OK.

     

    Dim Exp As New clsExpert

     

    Dim dt As DataTable = Exp.GetChildByProvider(UserID, ProviderID)

     

    If dt.Rows.Count > 0 Then

     

    With Me.tvNav

     

    .DataSource = dt

    .DataFieldID =

    "ID"

     

     

    .DataFieldParentID ="ParentID"

     

     

    .DataTextField = "Node"

     

     

    .DataValueField = "ChildID"

     

     

    .DataBind()

     

    .ExpandAllNodes()

     

    End With

     

     

    Else

     

     

    Me.lblNavStatus.Text = "No Children set up."

     

     

    End If

    This gives me a 2 level tree, with groups and children. How can I disable the top level nodes to stop users from clicking them and getting an error, as these first level nodes dont have any ID's associated with them.

    Andy

     

     

     

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 09 Dec 2008 Link to this post

    Hi,

    Try the following javascript code to prevent selection of the parent node.

    JS:
    <script type="text/javascript"
    function OnClientNodeClicking(sender, eventArgs) 
      var node = eventArgs.get_node();   
     
      if(node.get_nodes().get_count()>0) 
      { 
        eventArgs.set_cancel(true); 
       
       } 
       
      
    </script> 


    Thanks
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 16 Dec 2008 Link to this post

    Thanks for reply and appologies for not coming back sooner, battling with RadGrid hierarchy at the moment.

    I tried this and disabled all node, not just the top ones.

    Andy
  5. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 17 Dec 2008 Link to this post

    Hello Andy Green,

    Princy's code should work as expected. It would cancel the OnClientNodeClicking event of all nodes that have children.
    What exactly is the behavior that you see?

    Sincerely yours,
    Veselin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 22 Dec 2008 Link to this post

    Thanks Princy,

    Not sure what I did, but tried it again and it worked first time.

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