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

Change event: e.item is null

1 Answer 603 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
David A.
Top achievements
Rank 1
David A. asked on 18 Aug 2012, 06:39 PM
Hi,
1) I am using the following code in the Change event:
@(Html.Kendo().DropDownListFor(m => m.Page.PageSource)
                          .DataTextField("Text")
                          .DataValueField("Value")
                          .BindTo(Model.PageSourceList)
                          .Value(Model.Page.PageSource)
                          .Enable(!Model.Page.IsSystem)
                          .HtmlAttributes(new { id = "source" })
                          .Events(e=>e.Change(@<text>
                          function(e) {
                            alert(e.item);
                          }</text>)))

and I get "undefined" when I change the item in the select list.

2) Is there a way to have this event fire initally when the page loads?

Thank you,
David A

1 Answer, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 20 Aug 2012, 04:14 PM
Hello David,

 
Straight upto your questions:

1. The Change event of the Kendo DropDownList does not have "item" argument. If you need to get the selected data item, you can use the dataItem method. Check the API reference.

2. The DropDownList is designed to not raise change event on initial load. You can trigger it manually:

@(Html.Kendo().DropDownListFor(m => m.Page.PageSource)
                          //erased for brevity
                          .Events(e=>e.Change(@<text>
                          function(e) {
                            alert(e.item);
                          }</text>)))
 
<script>
      $(function() {
         var ddl = $("#Page_PageSource").data("kendoDropDownList");
          if (ddl) {  ddl.trigger("change"); }
      });
</script>

Regards,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
DropDownList
Asked by
David A.
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or