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

Option Label not Rendering

4 Answers 283 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 14 Aug 2013, 04:57 PM
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")))

4 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 16 Aug 2013, 10:17 AM
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!
0
Nick
Top achievements
Rank 1
answered on 16 Aug 2013, 12:57 PM
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.
0
Accepted
Vladimir Iliev
Telerik team
answered on 20 Aug 2013, 12:47 PM
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!
0
Nick
Top achievements
Rank 1
answered on 20 Aug 2013, 12:54 PM
Thank you Vladimir!
Tags
DropDownList
Asked by
Nick
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Nick
Top achievements
Rank 1
Share this question
or