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

DropDownList is losing text value in loop.

2 Answers 87 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 16 Dec 2013, 03:50 PM
I'm trying to use the same DropDownList widget multiple times within a loop in form for however many fleets a manager is assigned as shown  in the attachment. The first instance of the DropDownList displays correctly. After that it displays as a text box with the value, not the text. And no dropdown.

Here's the code I used for the widget.
        @(Html.Kendo().DropDownListFor(m => m.ManagerViewModel.ManagerId)
                .Name("ManagerDropDownList")
                .DataTextField("ManagerNameLast")
                .DataValueField("ManagerId")
                .HtmlAttributes(new { style = "width: 200px;" })
                .BindTo(Model.MgrsDropdownViewModel)
                )

And here is the page source for the first and second instances. The complete list of managers is shown for both instances. But the data-val properties are missing in the second instance. How do I get the data-val to show for every instance?

<input data-val="true" data-val-number="The&#32;field&#32;ManagerId&#32;must&#32;be&#32;a&#32;number." data-val-required="The&#32;ManagerId&#32;field&#32;is&#32;
required." id="ManagerDropDownList" name="ManagerDropDownList" style="width:&#32;200px;" type="text" value="80" /><script>
jQuery(function(){jQuery("#ManagerDropDownList").kendoDropDownList({"dataSource":[{"ManagerId":280,"ManagerNameLast":"AXXXXXXO,  JOHN           "},

<input id="ManagerDropDownList" name="ManagerDropDownList" style="width:&#32;200px;" type="text" value="80" /><script>
jQuery(function(){jQuery("#ManagerDropDownList").kendoDropDownList({"dataSource":[{"ManagerId":280,"ManagerNameLast":"AXXXXXXO            , JOHN           "},
 




     

2 Answers, 1 is accepted

Sort by
0
Accepted
Alexander Popov
Telerik team
answered on 18 Dec 2013, 10:18 AM
Hello William,

I noticed that the Name of the widgets is static and as a result there will be multiple HTML elements with the same ID. This will cause issues with widget initialization and binding, so I would recommend you to append a unique identifier to the Name, perhaps the fleet ID or number.

Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
William
Top achievements
Rank 1
answered on 18 Dec 2013, 12:28 PM
Thanks Alexander. It works great using the Location Id as part of the name .
Tags
DropDownList
Asked by
William
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
William
Top achievements
Rank 1
Share this question
or