Initialize drop down in TreeView template

5 posts, 1 answers
  1. Peter
    Peter avatar
    22 posts
    Member since:
    Jul 2013

    Posted 06 Aug 2013 Link to this post

    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
  2. Answer
    Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 08 Aug 2013 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Peter
    Peter avatar
    22 posts
    Member since:
    Jul 2013

    Posted 08 Aug 2013 Link to this post

    Hi;

    That did the job. Thanks.

    Peter
  5. Peter
    Peter avatar
    22 posts
    Member since:
    Jul 2013

    Posted 08 Aug 2013 Link to this post

    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
  6. Peter
    Peter avatar
    22 posts
    Member since:
    Jul 2013

    Posted 08 Aug 2013 Link to this post

    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
Back to Top
Kendo UI is VS 2017 Ready