This is a migrated thread and some comments may be shown as answers.

RAD Treeview Issue with unchecked node

8 Answers 250 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Asok
Top achievements
Rank 1
Asok asked on 08 Aug 2012, 07:46 PM
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

8 Answers, 1 is accepted

Sort by
0
Ivana
Telerik team
answered on 10 Aug 2012, 11:20 AM
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.
0
Asok
Top achievements
Rank 1
answered on 12 Aug 2012, 06:18 PM
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
0
Princy
Top achievements
Rank 2
answered on 13 Aug 2012, 07:33 AM
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.
0
Asok
Top achievements
Rank 1
answered on 13 Aug 2012, 12:00 PM
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
0
Shinu
Top achievements
Rank 2
answered on 14 Aug 2012, 07:16 AM
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
0
Asok
Top achievements
Rank 1
answered on 14 Aug 2012, 12:17 PM
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
0
Hana
Top achievements
Rank 1
answered on 20 Apr 2016, 03:11 AM

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

0
Ivan Danchev
Telerik team
answered on 22 Apr 2016, 07:25 AM
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.
Tags
TreeView
Asked by
Asok
Top achievements
Rank 1
Answers by
Ivana
Telerik team
Asok
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Hana
Top achievements
Rank 1
Ivan Danchev
Telerik team
Share this question
or