How to find the selected node is Parent Node or Child Node in tree view

15 posts, 0 answers
  1. sravanthi
    sravanthi avatar
    23 posts
    Member since:
    Aug 2010

    Posted 26 Aug 2011 Link to this post

    Hi,
    I want to know the checked Node is parent node or  Child node.Can I do that.
    Please let me know.
    I am having a tree view which is loaded by the sql datasource like this,
    <telerik:RadTreeView ID="tvwGroups" Height="320px" Width="300" runat="server" CheckBoxes="True" TabIndex="1"
                                DataSourceID="sdsTreeView" DataFieldID="CATGROUPID"  DataTextField="NAME" DataFieldParentID="PARENTID" OnNodeCheck="OnNodeCheck_tvwGroups">
                                    <DataBindings>
                                        <telerik:RadTreeNodeBinding TextField="NAME" ValueField="CATGROUPID" />
                                        <telerik:RadTreeNodeBinding Depth="0"  ValueField="CATGROUPID" TextField="NAME"/>
                                    </DataBindings>
                                </telerik:RadTreeView>
    I want to do different things based on the parent node and child node.


    Thanks,
    Sravanthi.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 29 Aug 2011 Link to this post

    Hello Sravanthi,

    You can achieve this by attaching NodeCheck event as shown below.
    C#:
    protected void RadTreeView1_NodeCheck(object sender, RadTreeNodeEventArgs e)
    {
         RadTreeNode node = e.Node;
          if (node.Checked)
         {
            string value = RadTreeView1.FindNodeByText("Node1").Text;
         }
    }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Silvia
    Silvia avatar
    7 posts
    Member since:
    Sep 2011

    Posted 19 Oct 2011 Link to this post

    Hi
    In java script can i do it?
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Oct 2011 Link to this post

    Hello Silvia,

    You can try the following javascript.

    JS:
    <script type="text/javascript">
    function OnClientNodeClicked(sender, args)
     {
       var node= sender.get_selectedNode();
       if (node._hasChildren()==true)
      {
          alert("has child");
      }
    }
    </script>
     
    Thanks,
    Shinu.
  6. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 20 Oct 2011 Link to this post

    Hi Silvia,

    You can find more information on the different client-side events that you can use with the RadTreeView control in the following help article - Client-Side Events

    Best wishes,
    Kate
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  7. Pawan
    Pawan avatar
    5 posts
    Member since:
    Feb 2012

    Posted 02 Feb 2012 Link to this post

    Hi,
    I am also trying to find out if the node is parent or not and then change its CssClass. I am trying it in NodeBound method. I don't see "Node" property in the list. Is there any other way to find out if the node is parent or not?
  8. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Feb 2012 Link to this post

    Hello,

    Try the following.
    JS:
    function OnClientLoad(sender, args)
     {
      var nodes = sender.get_allNodes();
       for (var i = 0; i < nodes.length; i++)
       {
         if (nodes[i].get_level() == 0)
         {
          if (nodes[i]._hasChildren() == true)
          {
           nodes[i].set_cssClass("parentcss");
          }
         }
     
        }
     }

    CSS:
    .parentcss
      {
        background:Red !important;
      }

    Thanks,
    Princy.
  9. Pawan
    Pawan avatar
    5 posts
    Member since:
    Feb 2012

    Posted 03 Feb 2012 Link to this post

    thanks princy for replying but I need more help. Can you give me the content of CSS to replace the +/- image to expand with custom image? I am trying with the following but it does not work.

    .RadTreeView_Test

     

    .rtPlus {

     

     

    background-image: url("../Images/OMSNav_FolderNode.gif");

     

    }

  10. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 03 Feb 2012 Link to this post

    Hello Pawan,

    Try the following CSS.
    CSS:
    <style type="text/css">
     .RadTreeView .rtPlus
    {
    background-image: url("Images/Node.gif") !important;
    }
    </style>

    -Shinu.
  11. Pawan
    Pawan avatar
    5 posts
    Member since:
    Feb 2012

    Posted 03 Feb 2012 Link to this post

    Isn't it similar to mine? I have tried it already. Does not work. :(
  12. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 03 Feb 2012 Link to this post

    Hello Pawan,

    Make sure that you use !important to override the default style.
    CSS:
    div.RadTreeView_Default .rtPlus, div.RadTreeView_Default .rtMinus
    {
      background-image: url("Images/Node.gif") !important ;
    }

    -Shinu.
  13. Pawan
    Pawan avatar
    5 posts
    Member since:
    Feb 2012

    Posted 03 Feb 2012 Link to this post

    Please let me know where am i going wrong. Below is my code.
    ascx
         div.RadTreeView_Default .rtPlus, div.RadTreeView_Default .rtMinus
    {
      background-image: url("../../../../Images/OMSNav_FolderCol.gif") !important ;
    }
      
    <rad:RadTreeView ID="RadTreeBU"  runat="server" OnNodeBound="RadTreeBU_NodeBound"    >                                          
                            </rad:RadTreeView
      
    .CS
      
    protected void RadTreeBU_NodeBound(object sender, RadTreeNodeEventArgs e)
            {
      
                e.NodeBound.CssClass = "RadTreeView_Default";
               // e.NodeBound.ImageExpandedUrl = "../Images/OMSNav_FolderExp.gif";
               //e.NodeBound.ImageUrl = "../Images/OMSNav_FolderCol.gif";      
      
            }

    I have also tried to add CssClass property in ascx file itself but in vain.
  14. Bozhidar
    Admin
    Bozhidar avatar
    1102 posts

    Posted 06 Feb 2012 Link to this post

    Hello Pawan,

    RadTreeView_Default is a class that's automatically added to the whole TreeView when it it created on the client. You don't have to add it yourself. If you use a skin, for instance "Web20", the name of this class is going to be RadTreeView_Web20.

    Remove the databound event from your tree and it should work as expected. Or you can try this example:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Functionality_TreeView_Default" %>
    <%@ Register tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head id="Head1" runat="server">
        <title></title>
        <style type="text/css">
         
            div.RadTreeView_Default .rtPlus, div.RadTreeView_Default .rtMinus
            {
                background-image: url("Image.jpg") !important ;
            }
         
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager runat="server" />
        <div>
         
            <telerik:RadTreeView ID="RadTreeView1" runat="server">
                <Nodes>
                    <telerik:RadTreeNode Text="Root">
                        <Nodes>
                            <telerik:RadTreeNode Text="Child">
                                <Nodes>
                                    <telerik:RadTreeNode Text="GrandChild" />
                                </Nodes>
                            </telerik:RadTreeNode>
                        </Nodes>
                    </telerik:RadTreeNode>
                </Nodes>
            </telerik:RadTreeView>
         
        </div>
        </form>
    </body>
    </html>

     
    Greetings,
    Bozhidar
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  15. Sunil
    Sunil avatar
    1 posts
    Member since:
    Sep 2011

    Posted 03 Mar 2014 Link to this post


    if (Tree_Chapter_List.SelectedNode.Level ==0  ) { RadMessageBox.Show("Please Select a chlid chapter", "Message"); return; }
  16. Virat
    Virat avatar
    1 posts
    Member since:
    Oct 2016

    Posted 21 Oct in reply to Princy Link to this post

    Hello madam please tell me theoraticaly on what basis the parent and child node is selected please tell me

    my mail id is "viratharish921@gmail.com"

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