views:

160

answers:

2

need javascript to set an selected index for RAD combobox to 0

+2  A: 

Have you tried "ClearSelections"?

var combo = $find("<%= RadComboBox1.ClientID %>");
combo.clearSelection();

EDIT

Give this a shot:

var combo = $find("<%= RadComboBox1.ClientID %>");
var comboItem = new Telerik.Web.UI.RadComboBoxItem();
combo.trackChanges();
combo.get_items().getItem(0).select();
combo.commitChanges();
Michael La Voie
Yes, I did but still not able to set it.
Nathan
Sorry, here is my situation, I have thd Raddropdown and I have "one","two",three" as items. my requirement is when I type the item in drop down it shuld display the text if the item is not there in the dropdown then the 0th index shld be selected.
Nathan
By 0 index do you mean the first item (which has a selectedindexid of 0)? If you have a real value saved in the 0 position, then to keep in the Telerik way of handling it, use the "selectedtext" and "selectedvalue" fields to get which item is selected regardless of whether they entered a new item or selected an existing item.
Michael La Voie
yes I mean the selectedIndexid of 0.can I have the java script the this. i made it work with codebehind. But I need the same functionlity in client side.Here is the psudoOn event OnClientDropDownClosed check if the typed value is there or not, If yes display the value else by default select the selectedindexid of 0
Nathan
You can enter custom text and get it through the client-side text property, but I don't know if you can have custom text and a selection at index zero, as that means two different things... It may need to be at -1 or null (whatever the client-side default is). I modified my response above.
Brian
still not working.. I will try and let you know if I get it worked.
Nathan
the above code is worked for OnClientDropDownClosing event. Thanks Michael..
Nathan
+1  A: 

Hey,

You should be able to do:

var combo = $find("<%= RadComboBox1.ClientID %>");
combo.get_items().get_item(0).select();

I believe you use get_item() to get the specific item. There is a selected index, but I've seen the preference being to use the select method instead on telerik forums.

EDIT: The RadComboBox uses the text property to reference the text in the combo, since the text isn't required to be an item in the list. You should test, because it's probably a selected index of -1. So, you can check and see if the selected index is a -1 or other value (not 100% sure if it's -1 or null on the client-side) and then programmably perform the selection. So is that the right response though, because I think the control then may wipe out your text...

Brian