I need to have a Telerik MVC grid with a combobox (in edit mode) that is populated based on criteria in each row. So when I click edit on one row, the resulting combobox will have items in it that will be different than the translator combobox in other rows. I figured this row should be loaded on demand, but I can’t figure out how to create a combobox in a grid without an editor template. It looks like I can’t pass parameters to an editor template.
Here’s the use case for this:
Imagine I have a list of languages with translators in a grid. When editing each row, a translator combobox would be displayed with only translators for that particular language. So French will have a translator combobox with names like Pierre, Francois, and Jacque, but Spanish will have names like Jose, Mario, and possibly Pierre because he speaks both French and Spanish.
Any ideas on how to achieve this with Telerik MVC Grid and Combobox?
Thanks in advance,
Steve
UPDATE:
Atanas,
Any chance you can provide a working example? I get errors. Here is my javascript based on your code:
function TaskGrid_OnEdit(e)
{
var combobox = $(e.row).find("#ComboBoxId").data("tComboBox");
//var values = getValuesForDataItem(e.dataItem); // get the values for the current data item
var values =
[
{ Text:"Product 1", Value:"1" },
{ Text:"Product 2", Value:"2" },
{ Text:"Product 3", Value:"3" },
];
combobox.dataBind(values); // fill the combobox
}
Here is the editor template, I don’t bind it to anything here:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Model.Data.tblJobTask>" %>
<%: Html.Telerik().DropDownListFor(s => s.SupplierID).Name("ComboBoxId") %>
By the way, the model in your editor template doesn’t map to any models you have in the solution. Should the model there be mapped to the data you are populating the combo with or the model of the list that’s populating the grid?
Steve
For embedding a combobox in a grid you can check this code library project (just replace the dropdownlist with a combobox). You still need to use an editor template though.
In order to populate the combobox with values specific to the current row you can use the OnEdit event of the grid. There you can setup the combobox using its dataBind method (to bind it client-side) or call its reload method to fill it using ajax. Here is some code: