RAD Treeview Issue with unchecked node

9 posts, 0 answers
  1. Asok
    Asok avatar
    7 posts
    Member since:
    Aug 2012

    Posted 08 Aug 2012 Link to this post

    Hello,

    I am using Telerik RadTreeview with checkboxes. I am saving the checked node ids to database. The scenario is when I select a particular dropdown I am making the checkboxes on the treeview selected based on the ids I get from the database. The issue revolves when I deselect a node and then on saving the Rad treeview it is still showing the checkbox as selected on the server side.

    Please advise!

    Thank you,
    Asok
  2. Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 10 Aug 2012 Link to this post

    Hello Asok,

    Can you paste here the troubled code? Or, send a sample project via a support ticket?

    Greetings,
    Ivana
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Asok
    Asok avatar
    7 posts
    Member since:
    Aug 2012

    Posted 12 Aug 2012 Link to this post

    Hello Ivana,

    Thank you for your response. The below is the code I am using.

    AXPX:

    <script type="text/javascript" language="javascript">
            function UpdateAllChildren(nodes, checked) {
                var i;
                var test;
                for (i = 0; i < nodes.get_count(); i++) {
                    if (checked) {
                        nodes.getNode(i).check();
                    }
                    else {
                        nodes.getNode(i).set_checked(false);
                    }


                    if (nodes.getNode(i).get_nodes().get_count() > 0) {
                        UpdateAllChildren(nodes.getNode(i).get_nodes(), checked);
                    }
                }
            }
            function clientNodeChecked(sender, eventArgs) {
                var childNodes = eventArgs.get_node().get_nodes();
                var isChecked = eventArgs.get_node().get_checked();
                UpdateAllChildren(childNodes, isChecked);
            }
     </script>

     <telerik:RadTreeView ID="permissionTreeView" runat="server" 
                            EnableDragAndDrop="false" EnableDragAndDropBetweenNodes="false"
                            Skin="Office2007" AllowNodeEditing="false" CheckBoxes="true" 
                            OnClientNodeChecked="clientNodeChecked" CheckChildNodes="true">                        
                        </telerik:RadTreeView>


    C#

    foreach( RadTreeNode node in permissionTreeView.CheckedNodes ) {
                        if( node.Checked ) {


                            if( node.Value.StartsWith( "f_" ) ) {
                                if( !rightsNodes.Contains( node.Value ) ) {
                                    _nodeIDs = _nodeIDs + node.Value.Replace( "f_", "" ) + ",";
                                    rightsNodes.Add( node.Value );


                                    if( node.Level != 0 ) {
                                        if( !parentNodes.Contains( node.ParentNode.Value ) ) {
                                            _parentNodeIDs = _parentNodeIDs + node.ParentNode.Value + ",";
                                            parentNodes.Add( node.ParentNode.Value );
                                        }
                                    }
                                }
                            }
                            else {
                                if( !parentNodes.Contains( node.Value ) ) {
                                    _parentNodeIDs = _parentNodeIDs + node.Value + ",";
                                    parentNodes.Add( node.Value );
                                }                            
                            }                        
                        }
                    }

    During the load I am populating the treeview and make some of the nodes checked based on the database values. When I unchecked a treeview node(using client side) , I am still getting it as checked in the checkdnodes collection list.

    Please advise!

    Thank you,
    Asok
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 13 Aug 2012 Link to this post

    Hi Asok,

    I was able to replicate the issue. I resolved that by Checking condition for postback in the pageload as follows. Please provide your full code if the issue persists.

    C#:
    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               // Your Code
            }  
        }

    Thanks,
    Princy.
  6. Asok
    Asok avatar
    7 posts
    Member since:
    Aug 2012

    Posted 13 Aug 2012 Link to this post

    Hello Princy,

    Thank you for your quick response. However it did not resolve my issue. To be more specific about my issue please see the below details.

    I want the checked nodeids that are checked on button save click. There are 2 drop downs used in the page. One is for role and other for users. When admin selects role, the users assigned with the roles get populated. On selecting a user drop down the permissions assigned to the selected user will be populated on the Treeview with nodeids checked. Now admin need to uncheck some and check few more, but in the checked node collection list I am getting the nodeids checked even when I deselected them.

    Thank you,
    Asok
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 14 Aug 2012 Link to this post

    Hi Asok,

    Unfortunately I couldn't replicate the issue. Here is the code that I tried based on your scenario which works as expected at my end.

    ASPX:
    <telerik:RadComboBox ID="cmbUsers" runat="server" AutoPostBack="true" onselectedindexchanged="cmbUsers_SelectedIndexChanged">
     <Items>
       .........
     </Items>
    </telerik:RadComboBox>
    <telerik:RadTreeView ID="permissionTreeView" runat="server"
             EnableDragAndDrop="false" EnableDragAndDropBetweenNodes="false"
             Skin="Office2007" AllowNodeEditing="false" CheckBoxes="true"
             OnClientNodeChecked="clientNodeChecked" CheckChildNodes="true">                       
    </telerik:RadTreeView>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" />

    C#:
    protected void Button1_Click(object sender, EventArgs e)
        {
            foreach (RadTreeNode node in permissionTreeView.CheckedNodes)
            {
                if (node.Checked)
                {
                    // Your Code
                }
            }
        }
     
    protected void cmbUsers_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            SqlDataAdapter adapter = new SqlDataAdapter("SELECT id,name,parent FROM tree",
                        ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
            DataSet permissions = new DataSet();
            adapter.Fill(permissions);
            permissionTreeView.DataTextField = "name";
            permissionTreeView.DataFieldID = "id";
            permissionTreeView.DataValueField = "id";
            permissionTreeView.DataFieldParentID = "parent";
     
            permissionTreeView.DataSource = permissions;
            permissionTreeView.DataBind();
            string state = values; // Get Saved Values From Database
            string[] arrPermissions;
            arrPermissions = state.Split(',');
            foreach (string Permission in arrPermissions)
            {
                // Your Code
            }
        }

    Hope this helps.

    Thanks,
    Shinu
  8. Asok
    Asok avatar
    7 posts
    Member since:
    Aug 2012

    Posted 14 Aug 2012 Link to this post

    Hello Shinu/Princy,

    Thank you for guiding me to the right solution. I used TreeNodeExpandMode.ServerSideCallBack to expand the child nodes. The problem still persists when I use the above. I changed it to TreeNodeExpandMode.ClientSide for the node expand mode and it works fine.

    Kindest Regards,
    Asok
  9. Hana
    Hana avatar
    1 posts
    Member since:
    Apr 2014

    Posted 19 Apr in reply to Asok Link to this post

    Hi

    I want the full solution of this problem for my project, because I can not solve it.

    Please send to me your solution in my email.

    hana_alamri@yahoo.com

  10. Ivan Danchev
    Admin
    Ivan Danchev avatar
    830 posts

    Posted 22 Apr Link to this post

    Hello Hana,

    Please open a support ticket and attach a runnable sample reproducing the issue you are having. You can follow our guidelines for isolating the issue.

    Regards,
    Ivan Danchev
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017