adding Treeview to combobox Programmatically

3 posts, 0 answers
  1. Bhupinder Singh
    Bhupinder Singh avatar
    13 posts
    Member since:
    Sep 2009

    Posted 16 Jul 2010 Link to this post


    I am trying to add a Programmtically databound Telerik TreeView in Combo Box just like you showed it in your tutorial for combo box application scenarios. I am trying to do this in a sharepoint webpart , that'S why I have to do every thing with code. I tried adding treeview to Combobox's controls collection, it did not work.
    Could you give me an example how to achieve this programmatically?


  2. Bhupinder Singh
    Bhupinder Singh avatar
    13 posts
    Member since:
    Sep 2009

    Posted 19 Jul 2010 Link to this post

    I was able to create a webpart using a usercontrol, now the problem is that once I select an item from treeview the it shows the selected item but all other items are gone? Could you tell me in which method I should bind the data again to the treeview control. Here is code sample

    1. ascx file
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI, Version=2009.3.1314.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4" %>
       <script type="text/javascript">
           function nodeClicking(sender, args) {
               var comboBox = $find("<%= RcbOrganization.ClientID %>");

               var node = args.get_node()




           function StopPropagation(e) {
               if (!e) {
                   e = window.event;

               e.cancelBubble = true;

           function OnClientDropDownOpenedHandler(sender, eventArgs) {
               var tree = sender.get_items().getItem(0).findControl("RtvOrganization");
               var selectedNode = tree.get_selectedNode();
               if (selectedNode) {
           var div1 = document.getElementById("TeamNetOrganization");
           div1.onclick = StopPropagation;

     <telerik:RadComboBox ID="RcbOrganization" runat="server" Height="140px" Width="215px"
                    ShowToggleImage="True" Style="vertical-align: middle;" OnClientDropDownOpened="OnClientDropDownOpenedHandler"
                    EmptyMessage="Choose a destination" ExpandAnimation-Type="None" CollapseAnimation-Type="None" Skin="Default" OnSelectedIndexChanged="RcbOrganization_IndexChanged">
                        <div id="TeamNetOrganization">
                            <telerik:RadTreeView runat="server" ID="RtvOrganization" OnClientNodeClicking="nodeClicking" Height="138px" Width="212px" >
                        <telerik:RadComboBoxItem Text="" />

    2. Code behind for user control:

    public void BindTreeView(IEnumerable<Organization> list)
                RadTreeView RtvOrganization = RcbOrganization.Items[0].FindControl("RtvOrganization") as RadTreeView;
                RtvOrganization.DataTextField = "TagName";
                RtvOrganization.DataFieldID = "TagName";
                RtvOrganization.DataFieldParentID = "ParentTagName";
                RtvOrganization.DataSource = list;

            protected void Page_Load(object sender, EventArgs e)
                if (!IsPostBack )
                    RcbOrganization.EmptyMessage = SPUtilities.GetResourceString("webpart_TeamNet_All_Organizations");
    3. web part which I use to bind data to treeview control.
    using (HcagSharePoint dataContext = new HcagSharePoint(SPUtilities.GetAdminSetting("DataConnection")))
                        organizationList = new List<Organization>();
                        foreach (TeamNetData teamNetData in list)
                            if (!string.IsNullOrEmpty(teamNetData.Organization))

                                foreach (string org in teamNetData.Organization.Split('|'))
                                    string organization = org;
                                    while (true)
                                        Organization tmpOrg = ((from o in dataContext.Organizations
                                                                where o.TagName.ToLower().Equals(organization.ToLower())
                                                                select o).FirstOrDefault());

                                        if (tmpOrg.ParentTagName == null)
                                        organization = tmpOrg.ParentTagName;

    Everything works fine, the only problem is after choosing one value other values are gone from the combo box.

  3. Kalina
    Kalina avatar
    918 posts

    Posted 23 Jul 2010 Link to this post

    Hello Bhupinder Singh,

    Please excuse us for delayed reply.

    I can suggest you set the DataText, DataTextField, DataFieldID,  DataFieldParentID and the  DataSource properties at every PageLoad event without calling explicitly DataBind() method.

    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