Cannot select DropDownList item in javascript

3 posts, 0 answers
  1. David
    David avatar
    18 posts
    Member since:
    Jun 2015

    Posted 28 Jul 2015 Link to this post

    Hi, I am using Kendo for ASP.Net MVC version 2015.2.264

    I am trying to set the selected value of a dropdown list programatically via javascript as follows, but it always returns null:

            var ddl = $("#selDFTAlignment").data("kendoDropDownList");
            if (ddl == null) { alert('null ddl'); return; }
            ddl.select("1");​

     

    I use the MVC wrappers to define the dropdown which generates the dropdown script as follows:

    jQuery(function(){jQuery("#selDTFAlignment").kendoDropDownList({"dataSource":[{"Text":"Left","Value":"0"},{"Text":"Centre","Value":"1"},{"Text":"Right","Value":"2"}],"dataTextField":"Text","template":"\u003cspan\u003e#:data.Text#\u003c/span\u003e","valueTemplate":"\u003cspan\u003e#:data.Text#\u003c/span\u003e","dataValueField":"Value"});});

     

    The dropdown list is inside a div container for a modal popup:

    <div id="mdlDefaultText" class="modal fade" role="dialog">​

     

    Why is the selector not working?  Am I missing something?  

  2. David
    David avatar
    18 posts
    Member since:
    Jun 2015

    Posted 28 Jul 2015 Link to this post

    I have tested the same code against a kendo dropdownlist defined directly using Kendo UI javascript rather than via the MVC wrapper, and the selector works perfectly against this dropdownlist, so the issue is with the MVC wrapper generated code.
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. David
    David avatar
    18 posts
    Member since:
    Jun 2015

    Posted 28 Jul 2015 Link to this post

    AArgghhhh ..... please ignore this - it was a typo on my part - I had transposed two letters in the dropdownlist name.
Back to Top