Couldn't select the default item from RadComboBox

3 posts, 0 answers
  1. nav100
    nav100 avatar
    48 posts
    Member since:
    Dec 2010

    Posted 11 Jan 2011 Link to this post

    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. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 14 Jan 2011 Link to this post

    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.
  3. nav100
    nav100 avatar
    48 posts
    Member since:
    Dec 2010

    Posted 20 Jan 2011 Link to this post

    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.
Back to Top