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

Dropdown value inside KendoGrid

3 Answers 236 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Victor
Top achievements
Rank 1
Victor asked on 23 Dec 2015, 06:09 PM

I have a Kendo grid which need a dropdown in some fields, i have used editor template for that (http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/editor-templates), everything is working fine, but when i select a value the grid shows the id of the dropdown element insted of its text value.

This is my partial view of the template

@(Html.Kendo().DropDownList()
        .Name("ClasificacionId")
        .DataValueField("Value")
        .DataTextField("Text")
        .BindTo((System.Collections.IEnumerable)ViewBag.ClasificacionId)
)

 

This is how i'm passing the list value to the view

 ViewBag.ClasificacionId = new SelectList(db.ClasificacionMercancia, "ClasificacionId", "Descripcion");

 

and this is how the row its defined in the kendo grid with razor sintax

.Columns(columns =>
                                       {                                          
                                           columns.Bound(o => o.ClasificacionId).Width(120).ClientTemplate("#= ClasificacionId #<input type='hidden' name='Fracion[#= index(data) #].ClasificacionId' value='#= ClasificacionId #'/>");

i need that Client template to save all editable kendo grid values to a List in my model, but i want to show the text value of the dropdown to the user insted of the id value.

3 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 24 Dec 2015, 12:56 PM

Hello Victor,

Is the text value part of the current model or is only the id value part of it? If only the id is part of the Grid model, you could use the approach demonstrated in the following foreign key column demo, in which a collection is passed, that could map each id value to the corresponding text value. Another possibility is to follow this custom editor demo, in which the whole object (in this case Category) is part of the Grid model.

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Victor
Top achievements
Rank 1
answered on 28 Dec 2015, 05:41 PM

I've already tried with this, actually this is the example i checked to do the dropdown inside the kendo grid, but i can access to a Text or Description property as the example (columns.Bound(p => p.Category).ClientTemplate("#=Category.CategoryName#").Width(160);)

cause it show 'undefined'

0
Dimiter Madjarov
Telerik team
answered on 04 Jan 2016, 09:51 AM

Hello Victor,

Are there any JavaScript errors in the browsers developer tools console, that could hint what is the problem? If the problem is still persisting, please send us small isolated runnable example that demonstrates it, so we could take a look at it locally.

Regards,
Dimiter Madjarov
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
Victor
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Victor
Top achievements
Rank 1
Share this question
or