How can I populate a telerik drop-down list at page load?
I get the following error(at emphasized line below) when I try to populate dropdownlist:
Error: 'data(...)' is null or not an object
Here is how I try to populate the telerik ddl:
$(function(){
var values = [];
for (var i = 1; i < 10; i++) {
values.push({ Text: i, Value: i });
}
****$("#MyDdl").data("tDropDownList").dataBind(values);****
});
Tried it this way as well:
$(function(){
onDataBinding();
});
function onDataBinding(e) {
var MyDdl = $('#MyDdl').data('tDropDownList');
var values = [];
for (var i = 1; i < 10; i++) {
values.push({ Text: i, Value: i });
}
****MyDdl.dataBind(values);****
};
But get following undefined error at emphasized line above:
Error: 'undefined' is null or not an object
Note: Adding a button and loading the ddl on button click event does populate telerik drop-down list. Doing it following way works perfectly fine, but cant seem to make it to work on page load. Also, When I bind it to a telerik datepicker's onload, it does populate the dropdownlist but makes it a static field 0r disables it, and hence cant select any values.
$(function(){
var values = [];
for (var i = 1; i < 10; i++) {
values.push({ Text: i, Value: i });
}
$("#MyDdl").data("tDropDownList").dataBind(values);
});
Any help is much appreciated.