Option Label not Rendering

5 posts, 1 answers
  1. Nick
    Nick avatar
    11 posts
    Member since:
    Jan 2013

    Posted 14 Aug 2013 Link to this post

    I am using the latest internal build (Kendo UI Complete v2013.2.814) of KendoUI and have noticed if I return empty lists to a dropdown the OptionLabel is no longer rendering correctly.

    Example Usage:

    @(Html.Kendo().DropDownListFor(model => model.EmploymentId)
                          .OptionLabel("* Not Selected")
                          .DataTextField("Name")
                          .DataValueField("Id")
                          .BindTo(Model.Employments)
                          .Events(e => e.Select("EmploymentSelected")))
  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 16 Aug 2013 Link to this post

    Hi Nick,

     
    Current behavior is expected and it's intended as when you bind to a empty array there are no other options in the DropDownList to choose from. 

    Kind Regards,
    Vladimir Iliev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Nick
    Nick avatar
    11 posts
    Member since:
    Jan 2013

    Posted 16 Aug 2013 Link to this post

    Thank you Vladimir.  In previous versions of the framework it would automatically render the OptionLabel if the datasource that it was bound too was empty.

    What is the best way to achieve this functionality again?

    Thank you.
  5. Answer
    Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 20 Aug 2013 Link to this post

    Hi Nick,

    As I mention in my previous reply current behavior is expected and it's intended when you bind the DropDownList to an empty array, however you can achieve the same behavior using the DataBound event:

    <script>   
        function onDataBound(e) {
            this.text(this.options.optionLabel);
        }
    </script>
     
             
    @(
     Html.Kendo().DropDownListFor(m => m)      
        .OptionLabel("-please select-")
        .Events(e => e.DataBound("onDataBound"))
        .BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"])
    )
    Kind Regards,
    Vladimir Iliev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Nick
    Nick avatar
    11 posts
    Member since:
    Jan 2013

    Posted 20 Aug 2013 Link to this post

    Thank you Vladimir!
Back to Top
UI for ASP.NET MVC is VS 2017 Ready