tags:

views:

3754

answers:

2

I'm using the latest 2009 RadCombobox Ajax control and I'm using the build in functionality to populate it from a webservice.

I would also like to push one more item to the box so the user has the choice of not choosing anything. Essentially making the control optional. Right now if they choose something and then change their mind, they can't change it back to nothing at all.

Everytime I've tried adding something it doesn't work or completely clears what was populated from the webservice. And I don't want the webservice to return and empty item just to make the control work.

<telerik:RadComboBox ID="combo" runat="server"
                    Skin="Office2007"
                    AllowCustomText="false"
                    EnableLoadOnDemand="true" 
                    AppendDataBoundItems="true" 
                    Text=""
                    Width="300" Height="200">
                    <ExpandAnimation Type="None" />
                    <CollapseAnimation Type="None" />
                    <WebServiceSettings Path="~/Service.asmx" Method="GetStuff" />

                </telerik:RadComboBox>

Thanks

+2  A: 

Is it something like this you have had in mind? Add an extra item after the data has been loaded.

  <script type="text/javascript">
    //<![CDATA[
    function OnClientItemsRequested(sender, eventArgs) {
      var combo = $find("<%= RadComboBox1.ClientID %>");
      var intextput = "<All Items>";
      var comboItem = new Telerik.Web.UI.RadComboBoxItem();
      comboItem.set_text(intextput);
      comboItem.set_value("-1");
      combo.trackChanges();

      combo.get_items().add(comboItem);
      comboItem.select();
      combo.commitChanges();
      comboItem.scrollIntoView();
    }
    //]]>
  </script>



 <telerik:RadComboBox runat="server" ID="RadComboBox1" 
      EnableLoadOnDemand="true" 
      OnClientItemsRequesting="OnClientItemsRequesting"
      OnClientItemsRequested="OnClientItemsRequested">
      <WebServiceSettings Method="GetMyData" Path="http://localhost:1606/Service1.asmx" />
    </telerik:RadComboBox>
Magnus Johansson
@Neil, that should be possible by hooking into the OnClientItemsRequesting event and add the item in that handler.
Magnus Johansson
A: 

Further to Magnus' answer, to add the item to the top you would do

combo.get_items().insert(0, comboItem);

Client-side documentation is here:

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

marijne