Selecting First Node from treeview and using to set combobox text and value.

2 posts, 0 answers
  1. Marc
    Marc avatar
    17 posts
    Member since:
    May 2009

    Posted 24 Apr 2011 Link to this post

    I have a treeview control embeded into a combobox. I am binding the tree to a sqldatasource, Then I select the first child node of the tree and set it as selected and this all works. What I haven't figured out is how to use the selected node of the tree and set the selected text/value of the parent combobox. I'm trying to do this server-side in c#.

    Also I would like to have the tree expanded to show the branch of the tree that has the selected node. If the user selects the dropdown then the tree would show the highlighted selected node.

    An example would be greatly appreciated.

    Thanks,

    Marc

     
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Apr 2011 Link to this post

    Hello Marc,
    Here is a sample code for achieving your first requirement.
    C#:
    protected void Page_Load(object sender, EventArgs e)
        {
             RadTreeView tree = (RadTreeView)RadComboBox4.Items[0].FindControl("RadTreeView1");
             RadTreeNode node = tree.FindNodeByText("Products");
             node.Selected = true;
             RadComboBox4.Text= node.Text;
        }
    aspx:
    <telerik:RadComboBox ID="RadComboBox4" runat="server" AllowCustomText="true">
               <ItemTemplate>
                   <telerik:RadTreeView ID="RadTreeView1" runat="server">
                       <Nodes>
                           <telerik:RadTreeNode Text="Products">
                           </telerik:RadTreeNode>
                           <telerik:RadTreeNode Text="Services">
                           </telerik:RadTreeNode>
                       </Nodes>
                   </telerik:RadTreeView>
               </ItemTemplate>
               <Items>
                   <telerik:RadComboBoxItem Text="" />
               </Items>
    </telerik:RadComboBox>

    I am not quite sure about your second requirement and please elaborate the scenario.

    Thanks,
    Shinu.
Back to Top