check only parent while binding the data

4 posts, 0 answers
  1. karamjeet
    karamjeet avatar
    8 posts
    Member since:
    May 2011

    Posted 08 May 2012 Link to this post

    I am using your RadTreeview to show my categories in parent child mode with code as

    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %><br><telerik:RadTreeView ID="RadTreeView1"<br>                                    runat="server" TriStateCheckBoxes="true" CheckBoxes="true" CheckChildNodes="false"><br>                                    <Nodes><br>                                    <telerik:RadTreeNode Text="hello" Value="hello"></telerik:RadTreeNode><br>                                    <telerik:RadTreeNode Text="hello1" Value="hello1" Selected="true" Checked="true"><br>                                    <Nodes><br>                                    <telerik:RadTreeNode Text="hello11" Value="hello11"></telerik:RadTreeNode><br>                                    <telerik:RadTreeNode Text="hello12" Value="hello12"></telerik:RadTreeNode><br>                                    <telerik:RadTreeNode Text="hello13" Value="hello13"></telerik:RadTreeNode><br>                                    </Nodes><br>                                    </telerik:RadTreeNode><br>                                    <telerik:RadTreeNode Text="hello2" Value="hello2"></telerik:RadTreeNode><br>                                    <telerik:RadTreeNode Text="hello3" Value="hello3"></telerik:RadTreeNode><br>                                    </Nodes><br>                                </telerik:RadTreeView>


    in code behind:
    i also checked but its not working

    RadTreeView1.ClearCheckedNodes();<br>RadTreeNode trnode = RadTreeView1.GetAllNodes().Where(tn => tn.Text=="hello1").FirstOrDefault();<br>                trnode.Selected = true;<br>               // trnode.Checkable = true;<br>                trnode.Checked = true;


    i want to check only parent while binding the data

    can anyone please help to tell me if i am doing something wrong, it is not possible or some kind of bug
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 May 2012 Link to this post

    Hi Karamjeet,

    Parent node in a RadTreeView with TriStateCheckBoxes checks only when the child nodes are checked. Please try setting TriStateCheckBoxes property of RadTreeView to false to check only the parent node while binding data as follows.

    ASPX:
    <telerik:RadTreeView ID="RadTreeView1" runat="server" TriStateCheckBoxes="false" CheckBoxes="true" CheckChildNodes="false">
      <Nodes>
         <telerik:RadTreeNode Text="hello" Value="hello">
         </telerik:RadTreeNode>
         <telerik:RadTreeNode Text="hello1" Value="hello1" Selected="true" Checked="true">
            <Nodes>
              <telerik:RadTreeNode Text="hello11" Value="hello11">
              </telerik:RadTreeNode>
              <telerik:RadTreeNode Text="hello12" Value="hello12">
              </telerik:RadTreeNode>
              <telerik:RadTreeNode Text="hello13" Value="hello13">
              </telerik:RadTreeNode>
           </Nodes>
         </telerik:RadTreeNode>
         <telerik:RadTreeNode Text="hello2" Value="hello2">
          </telerik:RadTreeNode>
          <telerik:RadTreeNode Text="hello3" Value="hello3">
          </telerik:RadTreeNode>
      </Nodes>
    </telerik:RadTreeView>

    C#:
    RadTreeView1.UncheckAllNodes();
    RadTreeNode trnode = RadTreeView1.GetAllNodes().Where(tn => tn.Text == "hello1").FirstOrDefault();
    trnode.Selected = true;
    trnode.Checked = true;

    Hope this helps.

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. karamjeet
    karamjeet avatar
    8 posts
    Member since:
    May 2011

    Posted 08 May 2012 Link to this post

    ok Thanks for your quick response

    But i also want that if someone check child node, parent should be checked
    which on checking the child working perfect but after when i disable tristate it will no longer check the parent

    Any workaround on this.


    And thanks for your quick response.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 09 May 2012 Link to this post

    Hi Karamjeet,

    Here is the sample code snippet that i tried to achieve your scenario.

    ASPX:
    <telerik:RadTreeView ID="RadTreeView1" runat="server" TriStateCheckBoxes="false" CheckBoxes="true"  OnClientNodeChecked="OnClientNodeChecked" CheckChildNodes="false">
      <Nodes>
         <telerik:RadTreeNode Text="hello" Value="hello">
         </telerik:RadTreeNode>
         <telerik:RadTreeNode Text="hello1" Value="hello1" Selected="true" Checked="true">
            <Nodes>
              <telerik:RadTreeNode Text="hello11" Value="hello11">
              </telerik:RadTreeNode>
              <telerik:RadTreeNode Text="hello12" Value="hello12">
              </telerik:RadTreeNode>
              <telerik:RadTreeNode Text="hello13" Value="hello13">
              </telerik:RadTreeNode>
           </Nodes>
         </telerik:RadTreeNode>
         <telerik:RadTreeNode Text="hello2" Value="hello2">
          </telerik:RadTreeNode>
          <telerik:RadTreeNode Text="hello3" Value="hello3">
          </telerik:RadTreeNode>
      </Nodes>
    </telerik:RadTreeView>

    JS:
    <script type="text/javascript">
        function OnClientNodeChecked(sender, args)
        {
            if (args.get_node().get_level() != 0)
            {
                args.get_node().get_parent().check();
            }
        }
    </script>

    C#:
    protected void Page_Load(object sender, EventArgs e)
        {
            RadTreeView1.UncheckAllNodes();
            RadTreeNode trnode = RadTreeView1.GetAllNodes().Where(tn => tn.Text == "hello1").FirstOrDefault();
            trnode.Selected = true;
            trnode.Checked = true;
        }

    Hope this helps.

    Thanks,
    Princy.
Back to Top