This is a migrated thread and some comments may be shown as answers.

Combobox value

6 Answers 108 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
mark
Top achievements
Rank 1
mark asked on 04 Dec 2008, 11:08 PM
Hi there,

I have gone through hundreds of pages trying to solve what seems like a simple problem.

status:
I have successfully put a treeview in a combobox, clicking of node populates combobox etc...

now for the problem.
I need to set the  text value of the combobox from a data source, I am successfully able to find the node in the treeview and select the node. hoping that would set my text value , unfortunately it didnt.

in the codebehind page I have even attempted to call a client function to set the text of the combo box.... still failed !!!


Does anyone know how to set the text value of the combobox when  the selected node of the embeded treeview  is changed at serverside?

many thanks

Mark


6 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 05 Dec 2008, 08:26 AM
Hello mark,

You could set the desired Text on the server as a Custom Attribute to the only Item of the ComboBox. Later, in the OnClientLoad event handler set the text of the ComboBox to that of the Attribute.

A similar approach is illustrated in this live demo, please use it as a reference.

Greetings,
Simon
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
mark
Top achievements
Rank 1
answered on 07 Dec 2008, 09:02 PM
Thanks Simon,

That pointed me in the right direction,

for anyone else looking at this, I have found another link that explains how to set custom attributes 

http://www.telerik.com/help/aspnet-ajax/combo_customattributes.html



how I solved it , I expanded on the  example treeview in a combobox (emphasis is on comboload.... )


[ASPX]

 

<

 

telerik:RadComboBox style="VERTICAL-ALIGN: middle" id="RadComboBox1" runat="server" OnClientDropDownOpened="OnClientDropDownOpenedHandler" OnClientLoad="comboLoad" Skin="WebBlue" ShowToggleImage="True" Width="250px" Height="140px">

 

 

 

 

 

 

<ItemTemplate>

 

 

 

 

 

 

<div id="div1" onclick="StopPropagation()">

 

 

<telerik:RadTreeView runat="server" ID="RadTreeView1" OnClientNodeClicking="nodeClicking"

 

 

 

 

 

 

Skin="WebBlue" Height="140px" Width="250px">

 

 

 

 

 

 

 

</telerik:RadTreeView>

 

 

 

 

 

 

</div>

 

 

 

 

 

 

</ItemTemplate>

 

 

 

 

 

 

<Items>

 

 

 

 

 

 

<telerik:RadComboBoxItem runat="server" />

 

 

 

 

 

 

</Items>

 

 

 

 

 

 

<CollapseAnimation Type="None" Duration="200" /><ExpandAnimation Type="None" />

 

 

</telerik:RadComboBox>

 

 

 


[Java script]
function

 

comboLoad(sender, eventArgs)

 

{

 

 

// sender.set_text(sender.get_items().getItem(0).get_value());  ---- this was the line in the demo 
// this is the new line  
sender.set_text(sender.get_attributes().getAttribute(

"TreeviewSelectedItem"));

 

 

}

[aspx.vb]

 

Protected

 

Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

 

    If

 

Me.RadComboBox1.Attributes.Item("TreeviewSelectedItem") Is Nothing Then

 

 

 

            Me.RadComboBox1.Attributes.Add("TreeviewSelectedItem", "Please Select")

 

 

    End If

 

End

 

Sub

 

0
Simon
Telerik team
answered on 08 Dec 2008, 09:50 AM
Hi mark,

Please have in mind that a custom attribute set in this way will be rendered on the <DIV> element of the ComboBox.

Your solution is possible however it will produce invalid HTML (<div ... TreeViewSelectedItem="...">).

Kind regards,
Simon
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
bad nick
Top achievements
Rank 1
answered on 18 Aug 2009, 11:07 AM
mark,

>Does anyone know how to set the text value of the combobox when  the selected node of the embeded treeview  is changed at serverside?

Yes, I was looking for solution and figured out the simplest way of doing this:
I've "moved" the code from function nodeClicking to a new function and called it from both, nodeClicking and comboLoad events:

        function nodeClicking(sender, args) { 
            selectNode(args.get_node()); 
        } 
 
        function comboLoad(sender, eventArgs) { 
            var tree = sender.get_items().getItem(0).findControl("RadTreeView1"); 
            var selectedNode = tree.get_selectedNode(); 
            selectNode(selectedNode); 
        }
        function selectNode(node) { 
            var comboBox = $find("<%= RadComboBox1.ClientID %>"); 
            comboBox.set_text(node.get_text()); 
            comboBox.trackChanges(); 
            comboBox.get_items().getItem(0).set_value(node.get_text()); 
            comboBox.commitChanges(); 
            comboBox.hideDropDown(); 
        } 

And, obviously assigned event to your RadCombobox:
<telerik:RadComboBox ID="RadComboBox1" ... OnClientLoad="comboLoad"

Hope this helps to others.

Rus
0
Hans van Rijnswoud
Top achievements
Rank 2
answered on 09 Apr 2010, 09:38 AM
Hi,

About the laste post : >Does anyone know how to set the text value of the combobox when  the selected node of the embeded treeview  is changed at serverside?


This is not a best way to do this basic action.
Is it not possible to do this on the server side ?

Something like : ComboBox.selectedValue = Treeview.selectedNode.value / text; ????

This is also strange that the selected value of a combobox the text is! This is for me not logical!

Any more easy solution for this please?


Thanks,

Edwin.
0
Simon
Telerik team
answered on 09 Apr 2010, 03:45 PM
Hello Edwin Blom,

Since there is only one Item in the RadComboBox in this case and it is selected, you can set its Text property to the value of the Node server-side. In this way the selected Node value will be shown in the RCB.

All the best,
Simon
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.
Tags
TreeView
Asked by
mark
Top achievements
Rank 1
Answers by
Simon
Telerik team
mark
Top achievements
Rank 1
bad nick
Top achievements
Rank 1
Hans van Rijnswoud
Top achievements
Rank 2
Share this question
or