How to Check/Selected Previous Selected Child Nodes

4 posts, 0 answers
  1. Venkata
    Venkata avatar
    128 posts
    Member since:
    Nov 2009

    Posted 02 Jan 2014 Link to this post

    I have a 2 Level(Parent & Child) Treeview.
    and i set Parent Node ExpandMode = TreeNodeExpandMode.ServerSide;

    How do we set Checked=true if user has previously selected Child nodes (lets assume i am getting the previous selected values from the Database)

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

    Posted 03 Jan 2014 Link to this post


    I guess you want to check the RadTreeView Child nodes based on the values from the database. Please have a look into the following code snippet. 

    <telerik:RadTreeView ID="RadTreeView1" runat="server">

    protected void Page_Load(object sender, EventArgs e)
        SqlDataAdapter adapter = new SqlDataAdapter("SELECT * from Details ", ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
        DataTable data = new DataTable();
        RadTreeView1.DataSource = data;
        RadTreeNodeBinding binding = new RadTreeNodeBinding();
        binding.CheckedField = "status";
        binding.Checkable = true;
        RadTreeView1.DataFieldID = "id";
        RadTreeView1.DataTextField = "text";
        RadTreeView1.DataFieldParentID = "parentid";
        RadTreeView1.CheckBoxes = true;

    Please provide your code if it doesn't help.
  3. Venkata
    Venkata avatar
    128 posts
    Member since:
    Nov 2009

    Posted 03 Jan 2014 Link to this post

    Thanks Princy But your solution doesn't help me

    here is my requirement.. User select some parent nodes and some child nodes and save to the database. while Edit we have to show/checked what he was selected previously. 

    here is my code:
    <telerik:RadTreeView ID="radTree" Height="250px" runat="server" CheckChildNodes="true" Skin="WebBlue" CheckBoxes="true" onnodeexpand="radTree_NodeExpand" >                                  

    private void LoadCompanyList()
    DataTable DT = GetData();            
    RadTreeNode nodeCompany = new RadTreeNode();
     foreach (DataRow row in DT.Rows)
       nodeCompany = new RadTreeNode(row["CName"].ToString(), row["CID"].ToString());
       nodeCompany.ExpandMode = TreeNodeExpandMode.ServerSide;

    protected void radTree_NodeExpand(object sender, RadTreeNodeEventArgs e)
                DataTable dtUsers = LoadUsers(Convert.ToInt32(e.Node.Value));
                foreach (DataRow row in dtUsers.Rows)
                    RadTreeNode treeUsers = new RadTreeNode(row["UName"].ToString(), row["UID"].ToString());                

    //while Editing we have to check/selected previous selected Company
    private void LoadPreviousSelectedCompanyList()
                string[] objSelectedCompany = getDataFrom Database();

                foreach (string strCompany in objSelectedCompany)
                    RadTreeNode foundNode = radTree.FindNodeByValue(strCompany);
                    if (foundNode != null)                                
                        foundNode.Checked = true;                

    But how do we set Previous Selected Userlist(Because until click on Node Expand we are not loading the Userlist)?
  4. Plamen
    Plamen avatar
    3025 posts

    Posted 08 Jan 2014 Link to this post

    Hi Venkata,

    You should set the checked property of the treeUsers node in NodeExpand event to true in case the node should be checked after populating.

    Hope this will help you solve the issue.

    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 the blog feed now.
Back to Top