How to Check/Selected Previous Selected Child Nodes

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

    Posted 02 Jan 2014 Link to this post

    Hi,
    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

    Hi,

    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. 

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

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

    Please provide your code if it doesn't help.
    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Venkata
    Venkata avatar
    126 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" >                                  
    </telerik:RadTreeView>

    private void LoadCompanyList()
    {
    DataTable DT = GetData();            
    radTree.Nodes.Clear();
    RadTreeNode nodeCompany = new RadTreeNode();
     
     foreach (DataRow row in DT.Rows)
      {
       nodeCompany = new RadTreeNode(row["CName"].ToString(), row["CID"].ToString());
       radTree.Nodes.Add(nodeCompany);
       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());                
                    e.Node.Nodes.Add(treeUsers);
                }           
            }

    //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)?
  5. Plamen
    Admin
    Plamen avatar
    2733 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.

    Regards,
    Plamen
    Telerik
    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