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

[Solved] How should I bind my Combo

1 Answer 100 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.
william
Top achievements
Rank 1
william asked on 29 Feb 2012, 01:35 PM
On initial entry (create) I want my combo to stay empty. Once the user has entered enough data, I force an Ajax/JQuery partial update on data from an @Html.EditorFor control.

it's at this point I want to trigger the population of the combo.

placing something like
.DataBinding(binding => binding.Ajax().Select("GetDropDownCC", "RoadRisk"))
on the combo will result in the method being performed regardless. I thought I might be able to do something on an 'onFocus' event but there isn't one.

How can I make this work such that the combo gets populated once I have placed a value into my EditorFor Control?

1 Answer, 1 is accepted

Sort by
0
william
Top achievements
Rank 1
answered on 29 Feb 2012, 04:39 PM
ok, I found at the bottom of this link how to attach on the fly.

http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-combobox-client-api-and-events.html

However, I really want to loop the returned object and build the data up. when I do this it just becomes one long string in the dropdown as it doesn't recognise the Text and Value part correctly it thinks this is part of the text:

var mydata = "";
                $.each(data.VehicleTypes, function (index, itemData) {
                    mydata = mydata + '{ Text: "' + itemData.Description +
                                     '", Value: "' + itemData.Id + '" },';
                });
                if (mydata.length > 0) {
                    mydata = mydata.substring(0, mydata.length - 1);
                }
                var dataSource = [
                    mydata
                ];
                telerikVehicles.dataBind(dataSource);
How should I build up mydata so that the control recognises the format correctly.
Tags
ComboBox
Asked by
william
Top achievements
Rank 1
Answers by
william
Top achievements
Rank 1
Share this question
or