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

[Solved] Dropdownlist template ajaxbound problem

2 Answers 180 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Joan Vilariño
Top achievements
Rank 2
Joan Vilariño asked on 19 May 2010, 03:30 PM
Hello.

I have a problem with dropdownlist templates in ajaxbound mode...

I use [UIHInt("myTemplate")] at the property like this:

public class myViewModel 
 
     public string Name { getset; } 
 
     [UIHint("AddressComboTemplate")] 
     public Address theAddress { getset; } 
 
 

Then I setup my grid:

   
    <%= Html.Telerik().Grid<myViewModel>()  
        .Name("myGrid") 
        .Pageable(page => page.PageSize(15) 
        .Position(GridPagerPosition.Both)) 
        .DataBinding(databinding => databinding.Ajax() 
            .Select("_Index","MotivoMovimientoSituacion")) 
        .Columns(columns => 
                     { 
                         columns.Bound(o => o.Name); 
                         columns.Bound(o => o.theAddress).ClientTemplate("<#=theAdress.Description#>"); 
                     }) 
        %> 

The Edit Template for my "Address" field (AddressComboTemplate.ascx) is:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Address>" %> 
<%= Html.DropDownListFor(o => o.Id, new SelectList(new AddressProxy().GetAll(),"Id","Description", (Model != null) : Model.Id ? String.Empty))%> 

At runtime, when you edit (ajax) a row, the template gets rendered, but the selected value of the combo is always the first of the list, instead the row's current value... I've found a workaround for this, tapping the 'click' event of the Edit button and setting the value of the dropdownlist to the right one, but it makes me adding extra javascript and a "OnClientDataRow" event for the grid on every grid with one or more dropdownlist combos.

Is this a bug, or am I doing anything wrong? 

Thanks!

2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 19 May 2010, 03:37 PM
Hi Joan VilariƱo,

The grid will not select the dropdown value in this case as the name of the dropdown is not the same as the name of the property. You can check the sample project attached in this forum thread for ideas how to set the value of the dropdownlist.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Joan Vilariño
Top achievements
Rank 2
answered on 19 May 2010, 03:52 PM
Ok... first thing first... the Name should be ok, since I get it automatically loaded at TryUpdateModel... that means that the form is sending the correct propertyname for the combo...

Second thing... you are doing something similar to what I was doing, the only difference is you access the grid data to get the item key, and i keep it in a tag in the <tr> at bind time...

So, from what you're telling me, if the <select> item has the correct name it would have to auto-set the right value on edit?

Thanks!
Tags
Grid
Asked by
Joan Vilariño
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
Joan Vilariño
Top achievements
Rank 2
Share this question
or