Creating a kendo dropdown list inside a kendo template

Mefhisto1 picture Mefhisto1 · Jun 17, 2014 · Viewed 7.9k times · Source
<script id="myTmpl" type="text/x-kendo-tmpl">
 <div id="myDropDown">
 </div>  

</script>

That's my small example of a code. Is there a way to create a drop down list on the div tag, since that div is not actually a DOM object, and therefore I cannot select with a Jquery selector ?

$('#myDropDown').kendoDropDownList // invalid, item doesn't exist.

I am not looking to make a drop down from HTML, because somewhere in my code I have data fetching for my dropdown, and it takes time to fetch that data. That's why I want to be able to do something like

$('#myDropDown').setDataSource //or however the correct syntax is. 

So 2 questions: How can I instantiate a kendo drop down from the template.

If that's not possible, how to 'have' a dataSourceChanged event for my dropdown list, so I can update the data on my dropdown list.

Answer

kryptonkal picture kryptonkal · Jun 17, 2014

In your template, include ToClientTemplate:

<script id="templateId" type="text/x-kendo-template">
   <div>
      @(Html.Kendo().DropDownList()
         ...
         .ToClientTemplate()
      )
   </div>
</script>