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

Binding Dropdownlist in ClientDetailTemplate

1 Answer 41 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gabriell
Top achievements
Rank 1
Gabriell asked on 25 May 2016, 07:25 PM

This really should be a minor but i cannot get it to work

I need to bind to a value (StatusId) from the parent row in my DropDownList

 

In my clientDetailTemplate i have

var parmStatusId = new HtmlString("#: StatusId #");
@Html.TextBox("txtBox", parmStatusId)  //this works just fine

@Html.DropDownList("myDropDownList", new SelectList(Model.StatusList, "Value", "Text", parmStatusId), string.Empty, new { @class = "form-control" }); //this doesnt work :-(

 

The source from the above is as following

 

<input id="txtBox" name="txtBox" type="text" value="#: StatusId #" />

<select class="form-control" name="1"><option value=""></option>
<option value="1">Ubehandlet</option>
<option value="2">Behandlet</option>
<option value="3">Lukket</option>
</select>

 

Am i missing the obvious??

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 30 May 2016, 07:30 AM

Hello Jesper,

Such approach will not work as the DropDownList helper will try to select the option on the server where the client-side template expression is not evaluated. Thus, no item will be selected.

Instead you could use the DetailInit event to set the value on the client-side. Similar to the following:

<script>
    function detailInit(e) {
        $(e.detailRow).find("select").val(e.data.StatusId);
    }
</script>

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Gabriell
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or