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

Populating RadComboBox with Web Service Dynamically

4 Answers 388 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Juan
Top achievements
Rank 1
Juan asked on 04 Sep 2012, 08:01 AM
Hey Peeps,

I have a bit of a problem here. I'm trying to populate a RadComboBox using a web service. It's working as expected however, some combo boxes needs to be populated dynamically. Basically I have three combo boxes on a page. The first combo box is populated using the standard ASP SqlDataSource object. The second combo box needs to be populated according to the selection of the first combo box and the third combo box needs to be populated according to the first and second combo box selections. All three combo boxes have their 'CheckBoxes' property set to true (multi selection required across all three combo boxes). I can manage the first two combo boxes using the SqlDataSource however I need to have something like the EnableLoadOnDemand function on the third combo box. If the client has selected ALL categories on the first combo box and ALL categories on the second combo box, then the third combo box will need to be populated with all available products (+/- 123 000 records). In a normal scenario using the SqlDataSource it takes a very long time to populate. I'm trying to find a way that will reduce loading time.

How do you suggest I approach this situation? What I've done so far is to create a web service to handle the data, but I need to specify the categories and sub categories so that the products are filtered correctly. Is there a way to refresh the web service on the combo box so that these items are populated correctly? (calling DataBind() does not affect the combo box when the LoadOnDemand is set to true).

The control:

<telerik:RadComboBox ID="cboSubCategories" runat="server" EmptyMessage="Select" AutoPostBack="true" OnSelectedIndexChanged="cboSubCategories_SelectedIndexChanged" AllowCustomText="true" Enabled="false" CheckBoxes="true" EnableCheckAllItemsCheckBox="true" EnableLoadOnDemand="false" EnableItemCaching="true" Width="324px">
                        <WebServiceSettings Path="ComboBoxWebService.asmx" Method="GetSubCategories"></WebServiceSettings>
                    </telerik:RadComboBox>

In the code-behind I'm trying to re-assign the web service settings:

string[] serviceInputArray = checkedValues.Split(';');
 
            ComboBoxWebService service = new ComboBoxWebService();
            service.SetSubCategoryValues(serviceInputArray);
 
            cboSubCategories.Enabled = true;
            cboSubCategories.EnableLoadOnDemand = true;

But with the above coding, the page returns an error 'Object reference not set to an instance of an object'. If I remove the coding, then the service populates nothing (because I'm not setting any values into the web service to retrieve categories from). When I don't set the <WebServiceSettings> into the control, and assign it in the code-behind, then the same error is shown.

Any solutions or suggestions will be greatly appreciated!

4 Answers, 1 is accepted

Sort by
0
Ivana
Telerik team
answered on 06 Sep 2012, 02:06 PM
Hello Juan,

Please note that the load-on-demand functionality along with CheckBoxes is not a supported scenario. The following help article explains more on the matter: http://www.telerik.com/help/aspnet-ajax/combobox-usability-checkboxes.html.

As for how to implement your scenario, the first and very important thing is to structure your database properly. In a related-RadComboBoxes scenario, when dealing with a large amount of data, it may be a better option if you do not allow the "All" option; this way there will not be a case where all the data need to be displayed in one RadComboBox. The following online demo shows a very good apprach to the related-RadComboBoxes scenario which you may find useful: http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/multiplecomboboxes/defaultcs.aspx.

I hope the information provided will be useful.

Kind regards,
Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Tom
Top achievements
Rank 1
answered on 18 Sep 2012, 02:38 PM
I am trying to repopulate a combobox by changeing the web service settings via javascript.

using the set_webServiceSettings method and a JSON string for the settings.
am getting stuck on the format of the JSON string. i am using this:

 '{"Method":"GetEmailAddressesWithStaff","Path":"WebPaths.WebService(WebPaths.WorkProWebServices.ReadWriteWebService)"}' 


and it is not working with this format. any help?
tg
0
Ivana
Telerik team
answered on 21 Sep 2012, 07:58 AM
Hello Tom,

The problem might be in the path definition -- you need to make sure that a valid path is given to the service. The following works perfectly at my end.
function clientLoad(sender) {
    sender.set_webServiceSettings('{"path":"Products.asmx","method":"GetCompanyNames"}');
}
<telerik:RadComboBox ID="RadComboBox1" runat="server" EnableLoadOnDemand="true" OnClientLoad="clientLoad">
    <%--<WebServiceSettings Method="GetCompanyNames" Path="Products.asmx" />--%>
</telerik:RadComboBox>


Regards,
Ivana
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Tom
Top achievements
Rank 1
answered on 21 Sep 2012, 08:02 AM
Ivana:
thanks for the reply.

the path is plucked from the cs file for the web service that should be called. it already works in that way. this was to switch it on the fly.

I would expect the setttings to be populated in the object during runtime and not function properly. currently they are blank.
no worries to everyone as i was able to get this working using a wholly different technique and this can be ignored/closed going forward.


thanks again for the reply.
Tags
ComboBox
Asked by
Juan
Top achievements
Rank 1
Answers by
Ivana
Telerik team
Tom
Top achievements
Rank 1
Share this question
or