Not able to retrive radioButtonList controll which is added to a RadTreeNode

2 posts, 0 answers
  1. Rony
    Rony avatar
    4 posts
    Member since:
    Sep 2010

    Posted 10 Sep 2010 Link to this post

    Hi,
          I have added a radionButtonList controll to a  RadTreeNode (Part 1). Now when i try to save the values according to the selected value of RadioButtonList , am not able to do that. Its not allowing me to convert that not back to a radiobutton list (part 2). I have added the code i used. Please correct me if am wrong and tell me how to achive it. 
    part 1) // adding RadioButtonList to treenode.

     

     

    RadTreeNode brandNode1 = new RadTreeNode(Name,Value);  // node

     

    RdTree_TeamBrand.Nodes.Add(brandNode1 );     // adding node to the tree -'RdTree_TeamBrand'

     

    RadioButtonList radioblist = new RadioButtonList(); //defining a radio btn list 

     

    radioblist.Items.Add(

    new ListItem("P", "1"));

     

    radioblist.Items.Add(

    new ListItem("S", "0"));

     

    brandNode1.Controls.Add(radioblist); // adding radioblist to controls of brandNode1

    part 2) // retriving the selected RadioButtonList value . This part not working. 
    RadioButtonList drplst = (RadioButtonList)RdTree_TeamBrand.Nodes[0].Controls[0]; // not working

     

                 or

     

     

    RadioButtonList drplst  = RdTree_TeamBrand.Nodes[0].Controls[0].FindControl(RdTree_TeamBrand.Nodes[0].Controls[0].ClientID)
    //some thing like this also not working

     

     

     

  2. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 14 Sep 2010 Link to this post

    Hi Rony,

    As I said in the previous 2 messages sent about this problem (also I include some suggestions based on information that I would not be able to get just from your post):

    The problem here is the following:
    - The nodes are templated in a wrong way!

    Currently your nodes are being templated once (on initial load of the page), while they should be templated on every postback too.
    The way to implement this would be:
    1. move the implementation of Page_Load handler in Page_Init time;
    2. add ParentId to your data source and create the nodes only through databinding;
    3. in Page_Init handler rebind the tree only if it's not postback;
    4. in the dataSource add a value column (nullable), and assign value which should indicate if the node should be templated or not;
    5. in Page_Init handler iterate through the nodes of the treeView (GetAllNodes would do the job to get all nodes in array and iterate through them) checking the value of the nodes, and by some criteria determining whether this node should be templated or not, and if it should be, then add the control in it's controls collection;
    6. when you try to get reference to the control inside the controls collection of a node, please, do it this way:
    RadioButtonList radio1 = (RadioButtonList)node2.FindControl("RadioButtonList1");

    Also after you get this to work, you probably will have to use a better style of templating - implementing ITemplate interface that we provide. Here is a nice little article on that: http://www.telerik.com/help/aspnet-ajax/tree_templatesruntime.html
    I recommend  that you use this way of templating (it even shows some of the above mentioned measures that you need to take, like moving templateing in Page_Init time and so on).

    Additional thought:
    - If you upgrade your controls, you can make use of the newly introduced event TemplateNeeded, not just over RadTreeView, but also over RadPanelBar, RadListBox, RadToolBar and on many others of the rest of the RadControls package.

    Please, try to implement the suggested and if you experience some problems during this process, don't hesitate to write to us again!

    Hope this is helpful for you!


    Regards,
    Nikolay Tsenkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top