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

[Solved] onComboBoxDataBound(e) view Combobox data

1 Answer 21 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
John
Top achievements
Rank 1
John asked on 05 Jul 2012, 12:04 PM
Hello

Hoping you can help please.

I have a one ComboBox that when selected cascades another combobox which loads it's elements via an AJAX call.
I.e.
<tr>
                        <td>@Html.LabelFor(model => model.CompanyId)</td>
                        <td>@(Html.Telerik().ComboBoxFor(model => model.CompanyId)
                            .BindTo(new SelectList(Lookup.ActiveExternalCompanies(), "Id", "Name"))
                            .Enable(true)
                            .Placeholder("-- Select One --")
                            .CascadeTo("RequestorId"))</td>
                        <td>@Html.ValidationMessageFor(model => model.CompanyId)</td>
                    </tr>
                    <tr>
                        <td>@Html.LabelFor(model => model.RequestorId)</td>
                        <td>@(Html.Telerik().ComboBoxFor(model => model.RequestorId)
                            .DataBinding(binding => binding.Ajax().Select("_CompanyUsers", "Quote"))
                            .ClientEvents(events => events
                                  .OnDataBound("onComboBoxDataBound")
                            )
                            .Placeholder("-- Select One --")
                            .Value("")
                            .CascadeTo("RfqTypeId"))</td>
                        <td>@Html.ValidationMessageFor(model => model.RequestorId)</td>
                    </tr>

I.e. when a selection is made in the first combobox the other makes an AJAX call to retrieve the data.
Everything works perfect, however,
The second combobox remains disabled if no data is returned from the AJAX call.
I would like to inform the user of this because the current situation is not intuitive, it looks like the UI has frozen.

A) Is there a way to alert the user of this when it happens using Telerik syntax?
or (alternatively)
B) in my javascript handler,  'e' is passed in the the function (e.data is always null by the way). Can I count the elements returned or even access the JSON object returned? I don't know what e is as such.

function onComboBoxDataBound(e) {
     //what can 'e' tell me?
 }

Any comments welcome.....

Thanks very much
J


1 Answer, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 05 Jul 2012, 06:27 PM
I found the solution to be:

function onComboBoxDataBound(e) {
     var elementCount = $(this).data("tComboBox").dropDown.$element.find("ul").find('li').size();
      if (elementCount == 0) {
          //This combobox has no elements
      }
 }

I've detailed the entire thing here for anyone who comes against the same problem.

http://outbottle.com/telerik-asp-net-mvc-count-the-number-of-elements-in-a-combobox-dropdownlist-or-autocomplete-ui-component/ 

Thanks
Tags
ComboBox
Asked by
John
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Share this question
or