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

Couldn't select the default item from RadComboBox

2 Answers 44 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
nav100
Top achievements
Rank 1
nav100 asked on 11 Jan 2011, 06:31 PM
I am trying to add default item 'All' to my RadComboBox. It is adding at the end and also it doesn't select this default item. What could be the problem? Are there any other ways to do it? 

function OnClientItemsRequested(sender, eventArgs) {  
     
var combo = $find("<%= RadComboBox1.ClientID %>");  
     
var intextput = "All";  
     
var comboItem = new Telerik.Web.UI.RadComboBoxItem();  
      comboItem
.set_text(intextput);  
      comboItem
.set_value("");  
      combo
.trackChanges();  
 
      combo
.get_items().add(comboItem);  
      comboItem
.select();  
      combo
.commitChanges();  
      comboItem
.scrollIntoView();  
   
}  
 
 
<telerik:RadComboBox runat="server" ID="RadComboBox1"   
     
EnableLoadOnDemand="true"   
     
OnClientItemsRequested="OnClientItemsRequested">  
     
<WebServiceSettings Method="GetMyData" Path="http://localhost:1606/Service1.svc" />  
   
</telerik:RadComboBox> 
 
I also tried with the following option. It adds the 'All' but it doesn't append the values from the database.


 <telerik:RadComboBox runat="server" ID="RadComboBox1"   
     
EnableLoadOnDemand="true"
   
      AppendDataBoundItems="true"
>
 
     
<WebServiceSettings Method="GetMyData" Path="http://localhost:1606/Service1.svc" />
 
       <Items>
             <telerik:RadComboBoxItem runat="server" Text="All" Value=""/>
       </Items> 
   
</telerik:RadComboBox>
 

2 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 14 Jan 2011, 02:24 PM
Hello Nara,

Try this:

function OnClientItemsRequested(sender, eventArgs) {  
      var combo = $find("<%= RadComboBox1.ClientID %>");  
      var intextput = "All";  
      var comboItem = new Telerik.Web.UI.RadComboBoxItem();  
      comboItem.set_text(intextput);  
      comboItem.set_value("");  
      combo.trackChanges();  
   
      combo.get_items().insert(0,comboItem);  
      combo.get_items().getItem(0).select()
      combo.commitChanges();  
    }  

I don't believe adding comboItem to the list and then trying to call select on it will select the one passed into the list. So I just retrieve the one I adding to the list and call select. I also removed the scrollIntoView method, since the RadComboBoxItem does not have such a method.

I hope that helps.
0
nav100
Top achievements
Rank 1
answered on 20 Jan 2011, 04:18 PM
Cori,

I tried the code but it doesn't get selected when the Page loaded. RadcomboBox shows empty. When I click on dropdown then it shows 'All'. I would like to see 'All' by default when page loaded. Is it possible?

Thanks for your help.
Tags
ComboBox
Asked by
nav100
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
nav100
Top achievements
Rank 1
Share this question
or