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

[Solved] Set SelectedIndex for nested Dropdownlist in MVC Grid (on the client)

2 Answers 119 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.
Jean
Top achievements
Rank 1
Jean asked on 26 Mar 2012, 06:40 PM

My issue is that I need to set the selected value of a nested DropDownList inside a Telerik MVC Grid Control. Since the grid is bound on the client I need to set the selected item of the dropdown list in the "onDrpLoad" event on the client.

What would be the correct way to set the selected index for the dropdown list below? It is also important that when the selected item in the dropdown list is set is does NOT cause the "onDrpChange" event to fire. The "onDrpChange" event also needs to access(send to the server) the AssistantId of the assistant that was selected when the event fires.

Is there a clean simple way to do this?

Html.Telerik().Grid<Person>()
.Name("Grid)
.DataBinding(dataBinding => dataBinding.Ajax().Select("GetDetails","Person"))
.Columns(columns =>                  
columns.Bound(p => p.AssistantId).ClientTemplate(
 Html.Telerik().DropDownList()
 .Name("AssistantList_<#= PersonId #>")
 .BindTo(new SelectList(AssistantController.GetAssistants()))
 .ClientEvents(events =>
  events.OnLoad("onDrpLoad");
  events.OnChange("onDrpChange");
 )
 .ToHtmlString()
);

Thanks.

2 Answers, 1 is accepted

Sort by
0
Accepted
Dadv
Top achievements
Rank 1
answered on 27 Mar 2012, 08:45 AM
Hi,
do you try this ?
0
Jean
Top achievements
Rank 1
answered on 27 Mar 2012, 01:32 PM
Thanks,

That was the correct way to go. i.e. for the client side bound grid, the only way to set the correct index on the nexted dropdown and get the required update behaviour was to use the new ForeignKey column feature. I wanted to avoid having the "Command button" column, but having this column has its benifits. i.e. the user knows that the update has been successful because the column resets itself.
Tags
Grid
Asked by
Jean
Top achievements
Rank 1
Answers by
Dadv
Top achievements
Rank 1
Jean
Top achievements
Rank 1
Share this question
or