Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Items to Telerik Ajax RadComboBox after populated from webservice

Tags:

c#

telerik

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

like image 309
Ryu Avatar asked Feb 28 '23 17:02

Ryu


1 Answers

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>
like image 70
Magnus Johansson Avatar answered Mar 03 '23 05:03

Magnus Johansson