2
votes

I have a drop down list in a kendo grid with client template column. I want to bind data from model that I pass to the view, but data is different for each kendo grid rows. I don“t know the correct syntax to do this. AvailableValues is a list of objects with value property. That value is that i want to use to populate my dropdownlist.

columns.Bound(c => c.Value).ClientTemplate(
                    Html.Kendo().DropDownList()
                        .Name("valueDrop_#=Name")
                        .DataTextField("Value")
                        .DataValueField("Value")
                        .OptionLabel("PleaseChoose")
                        .HtmlAttributes(new { @class = "wide-full bodyTypeDrop" })
                        .BindTo(AvailableValues)//syntax???
                        .ToClientTemplate().ToHtmlString()
                    );

Is any solution to to this without define ajax read function for each dropdown list?

1

1 Answers

1
votes

I actually had to this exact thing in one of my projects.

At the top of your page:

List<YourModel> AvailableValues = YourModel.Read();

Then in the Grid:

columns.Bound(c => c.Value).ClientTemplate(
                                Html.Kendo().DropDownList()
                                    .Name("valueDrop_#=Name#")
                                    .DataTextField("Value")
                                    .DataValueField("Value")
                                    .OptionLabel("PleaseChoose")
                                    .Value("#= LocalModelValue #")
                                    .BindTo(AvailableValues)
                                    .HtmlAttributes(new { @class = "wide-full bodyTypeDrop" }).ToClientTemplate().ToHtmlString()
                                );

The .Value("#= LocalModelValue #") is for the object's local value. E.g. if the current row's LocalModelValue is 5, the dropdown will select the 5th value.

Hope this helps!