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
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.
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
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.
>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
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.
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.