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

Initialize drop down in TreeView template

4 Answers 168 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 06 Aug 2013, 06:02 PM
Hi;

I have a [Kendo] ListView in a [razor] view. I have a drop down as part of the ListView template. I can get the drop down loaded with an enumeration list and can bind to the onchange event. What is not happening is the combo box is not being initialized with the specified value in the bound data object [to each row of the list view].My ListView template is as such.<script type="text/x-kendo-template" id="GroupUserMappingTemplate">

<div>
@Html.DropDownList(
"AccessLevel",
new SelectList(Enum.GetValues(typeof(P3X_DataAccess.Models.AccessLevel))),
new {
onchange = "(AccessLevelChanged(this));"
}
)
</div>
</script>
The property the combo box is initialized to is called AccessLevel. It is the name of the property that is in the object that is bound to the List View rows, and I assume is valid for use as the bound property. The binding does not occur (but no errors occur either).

Peter

4 Answers, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 08 Aug 2013, 11:31 AM
Hello Peter,

Making the option select based on the row item cannot be done in such way , because to make an item initially selected you need to add the selected option to its list.

However if you use the Kendo DropDownList you can achieve it like this:

@(Html.Kendo().DropDownList()
            .Name("AccessLevel#=UnitPrice#")
        .BindTo(
        new SelectList(new[]{"foo","18"}))
        .Value("#= UnitPrice #")
       .ToClientTemplate()
)

Of course you will need to once again use the change event of the DropDownList to manually update the underlying dataitem with the selected value of the DropDownList.

Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Peter
Top achievements
Rank 1
answered on 08 Aug 2013, 08:06 PM
Hi;

That did the job. Thanks.

Peter
0
Peter
Top achievements
Rank 1
answered on 08 Aug 2013, 10:48 PM
Hi;

I just found an issue with using a Kendo dropdown control. The drop down only fills with the drop down items for the first record in the List. I checked the data records and they are valid. Why would the drop down only fill the list for the first row? I have attached a screen shot of what I'm seeing. The template I'm using for the list view follows:
-----------------------------------------------------------------------------------------------------------------------------------------------
<script type="text/x-kendo-template" id="GroupUserMappingTemplate"> 
 
    <table style="width:100%; border-collapse: collapse;">
   <tr>
   <td style="padding-top: 0;padding-bottom: 0;">
    #:UserAlias#
   </td>
   
            <td style="padding-top: 0;padding-bottom: 0;">
    @Resources.ActiveLabel
   </td>   <td style="width:1%;padding-top: 0;padding-bottom: 0;">               
    <input style="padding-top: 0;padding-bottom: 0;" type="checkbox" data-bind="check:IsActive"   #= IsActive ? checked="checked" : "" # onclick="UserActiveChanged(this)"  />            
   </td>
   
            <td style="padding-top: 0;padding-bottom: 0;">
    @Resources.IsAdminLabel
   </td>                       
           
            <td style="width:1%;padding-top: 0;padding-bottom: 0;">               
    <input style="padding-top: 0;padding-bottom: 0;" type="checkbox" data-bind="check:IsAdmin"   #= IsAdmin ? checked="checked" : "" #  onclick="UserIsAdminChanged(this)" />            
   </td>            <td style="padding-top: 0;padding-bottom: 0;">
    @Resources.AccessLevelLabel
   </td>                       
           
            <td>
                 @(Html.Kendo().DropDownList()
                    .Name("AccessLevelName#=AccessLevelName#")                                       
                    .BindTo(Enum.GetNames(typeof(P3X_DataAccess.Models.AccessLevel)).ToList())
                    .Value("#:AccessLevelName#")
                    .Events
                    (
                        e => e.Change("AccessLevelChanged")
                    )                   
                    .ToClientTemplate()    
                                                 
                )
   </td>                                   
  </tr>
 </table>        
      
</script>

-----------------------------------------------------------------------------------------------------------------------------------------------

Peter
0
Peter
Top achievements
Rank 1
answered on 08 Aug 2013, 11:35 PM
Ok; I found out that DropDown controls must have a unique name [if more than one exist on the same page/form]. Just make sure that the dropdown's use a dynamic name when constructing within a listview. This should be more apparent then it is.

Peter
Tags
ListView
Asked by
Peter
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Peter
Top achievements
Rank 1
Share this question
or