Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > ComboBox > ComboBox with Treeview copy values from one combobox to the other

Not answered ComboBox with Treeview copy values from one combobox to the other

Feed from this thread
  • Aleksander avatar

    Posted on Feb 2, 2012 (permalink)

    I have 2 combo boxes with treeviews in them for a States drop down list and when I click a button, I would like the first combobox to copy the value and text to the second one as well as select the appropriate node and expand to it if needed. The combo box is a list of states and then the only parent is Territories which then shows the US territories. The code I have is as follows.

    My markup is as follows...

    function nodeClicking(sender, args) {
                var temp = sender._clientStateFieldID.split('_');
                if (temp.length >= 1) {
                    var name = temp[0];
                    var comboBox = $find(name);
     
                    var node = args.get_node();
     
                    comboBox.set_text(node.get_text());
     
                    comboBox.trackChanges();
                    comboBox.get_items().getItem(0).set_text(node.get_text());
                    comboBox.get_items().getItem(0).set_value(node.get_value());
                    comboBox.commitChanges();
     
                    comboBox.hideDropDown();
                }
            }
     
    <div style="width: 100%;">
                <tk:RadComboBox ID="rcbState" runat="server" Width="250px" ShowToggleImage="true" EmptyMessage="Choose a State"
                    HighlightTemplatedItems="true" style="vertical-align: middle;" >
                    <ItemTemplate>
                        <div id="div1">
                            <tk:RadTreeView ID="rtvState" runat="server" OnClientNodeClicking="nodeClicking">
                                <DataBindings>
                                    <tk:RadTreeNodeBinding Expanded="false" />
                                </DataBindings>
                            </tk:RadTreeView>
                        </div>
                    </ItemTemplate>
                    <Items>
                        <telerik:RadComboBoxItem Text="" />
                    </Items>
                </tk:RadComboBox>
                <asp:Label ID="lblTest" runat="server" />
            </div>
     
            <div>
                <tk:RadComboBox ID="rcbState2" runat="server" Width="250px" ShowToggleImage="true" EmptyMessage="Choose a State"
                    HighlightTemplatedItems="true" style="vertical-align: middle;" >
                    <ItemTemplate>
                        <div id="div1">
                            <tk:RadTreeView ID="rtvState2" runat="server" OnClientNodeClicking="nodeClicking">
                                <DataBindings>
                                    <tk:RadTreeNodeBinding Expanded="false" />
                                </DataBindings>
                            </tk:RadTreeView>
                        </div>
                    </ItemTemplate>
                    <Items>
                        <telerik:RadComboBoxItem Text="" />
                    </Items>
                </tk:RadComboBox>
                <asp:Label ID="lblTest2" runat="server" />
            </div>
     
            <div>
                <tk:RadButton ID="btnTest" runat="server" Text="Submit" OnClick="btnTest_Click" />
            </div>

    Then code behind is...

    protected void btnTest_Click(object sender, EventArgs e)
        {
            string text = rcbState.SelectedItem.Text;
            string value = rcbState.SelectedItem.Value;
     
            lblTest.Text = "Name = " + text + ", ID = " + value;
     
            rcbState2.Text = text;
     
            RadTreeView rtv2 = rcbState2.Items[0].FindControl("rtvState2") as RadTreeView;
     
            (rtv2.Nodes.FindNodeByValue(value)).Expanded = true;
     
            if (rcbState2.SelectedItem != null)
            {
                lblTest2.Text = rcbState2.SelectedItem.Text;
                lblTest2.Text = rcbState2.SelectedItem.Value;
            }
        }

    I'm having 2 problems... 1 is when i click the button the first time it'll get the text and value from the combo box but on the second time around it's null. 2 is I can't get the second state combobox to set the text and value and the selected item value.

    Reply

  • Posted on Feb 3, 2012 (permalink)

    Hello,

    Try the following code snippet.
    C#:
    protected void Button1_Click(object sender, EventArgs e)
       {
          string value = RadComboBox1.SelectedItem.Value;
           string text = RadComboBox1.SelectedItem.Text;
           RadComboBox2.SelectedItem.Text = text;
           RadComboBox2.SelectedValue = value;
           RadTreeView RadTreeView2= RadComboBox2.Items[0].FindControl("RadTreeView2") as RadTreeView;
           if (RadTreeView2.FindNodeByText(text).Level>0) //to check whether it is a parent node or not
           {
               RadTreeView2.FindNodeByText(text).ParentNode.Expanded = true;
               RadTreeView2.FindNodeByText(text).Selected = true;
           }
           else
           {
               RadTreeView2.FindNodeByText(text).Selected = true;
           }
       }

    Thanks,
    Princy.

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > ComboBox > ComboBox with Treeview copy values from one combobox to the other
Related resources for "ComboBox with Treeview copy values from one combobox to the other"

ASP.NET ComboBox Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  |  Step-by-step Tutorial  ]