In the model I pass to my view I have a list of Users, that I want to link to a dropdownlist called UsuariosDrpDwn
and show it in a certain column("Usuario") of every row of my grid ( marked bold).
I program the dropdownlist and it populates allright with the users, but when I link it to one of my grid's columns("Usuario"), the problem is it's values spread along the rows of the grid. Let's say my users are John, Martha, Grant, Michael. What happens is, John appears in the column "Usuario" of the first row, Martha in the column Usuario of the second row, Grant in the column Usuario of the third row, and Michael in the fourth.
These is the code for the dropdownlist:
@(Html.Kendo().DropDownListFor(d=>d)
.Name("UsuariosDrpDwn").HtmlAttributes(new { @style = "font-size:12px" })
.DataTextField("NombreUsuario")
.DataValueField("IdUsuario")
.BindTo(Model)
)
And this the code for my grid, I mark bold the column that is bounded to the dropdownlist:
@(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns=>
{
columns.Bound(d => d.BorradoLogico).Title("Borrado logico");
columns.Bound(d => d.FTick).Title("Ftick");
columns.Bound(d => d.NombreUsuario).Title("Usuario").EditorTemplateName("UsersDrpDwn");
@columns.Command(command => { command.Edit(); command.Destroy(); }).Width(172);
})
I attach my view.
7 Answers, 1 is accepted
Could you please clarify what "the problem is it's values spread along the rows of the grid" means? A screenshot would help a lot.
Regards,Atanas Korchev
Telerik
It's values are Alfonso(appears twice) and Juan (appears twice).
The column of the grid where the values of the dropdownlist spread along is called Usuario( marked with a red circle). As you can see in the photo, the users spread along the grid's rows. Alfonso in the first row of the grid, Alfonso again in the second row, then Juan in the third row of the grid, and again Juan in the fourth row . What I want is the dropdown to show in every cell Usuario of every row in the grid, being able to see all the users in it.
The editor template will appear only when the current grid row is in edit mode. What happens when you click the edit button? Does the dropdown appear?
The only problem I see is that you are setting the name of the dropdownlist in the editor template. When you use DropDownListFor the name is set automatically. Here is how the updated code should look like:
@(Html.Kendo().DropDownListFor(d=>d)
.DataTextField("NombreUsuario")
.DataValueField("IdUsuario")
.BindTo(Model)
)
In addition you can check the following online demos:
http://demos.kendoui.com/web/grid/editing-custom.html
http://demos.kendoui.com/web/grid/foreignkeycolumn.html
The help article about using editor templates could also be of help for you: http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/editor-templates
If you need further assistance please attach a runnable version of your project to this forum thread. We will troubleshoot it for you and see what went wrong.
Atanas Korchev
Telerik
A runnable version means a project which we can run at our side without any modifications or restoring database backups.
Regards,Atanas Korchev
Telerik
It would be enough if we can run your project without any modifications and reproduce the problem you are having. Of course we can't tell that before we have the files.
Regards,Atanas Korchev
Telerik