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

DropdownlistFor in Dynamic Grid

1 Answer 234 Views
Grid
This is a migrated thread and some comments may be shown as answers.
FposUser
Top achievements
Rank 1
FposUser asked on 20 Aug 2015, 03:55 PM

I am creating a Dynamic Kendo Grid using GridBoundColumnBuilder().
I loop through all of the controls on the previous page to create the grid. For example with myTextbox(), myCheckbox(), etc.
These create columns in the grid. I have all of the columns creating and populating with data.
My issue is with the Dropdownlist and the Multiselect list, they populate with data but do not display the correct data when the grid is created. The dropdown list displays the value, not the text of the previous control:
1 = My 2 = Data
The Dropdownlist will display 1 instead of My. And, the Multiselect only displays [object Object].
When you click on either of the controls in the grid it switches to show the proper text, but loses it when you click off.
Any ideas of what I am doing wrong?

 

 

foreach (ControlBase control in flatColumns)
 {
      GridBoundColumnBuilder<dynamic> thisColumn;
      if (control.Lookups != null && control.Lookups.Any())
           {
                if (!control.IsMultiSelect){
                     thisColumn = column.Bound(control.ControlType, control.ColumnName).Title(control.Description);
                            thisColumn.EditorTemplateName("DropDownList");
                            thisColumn.Width(250);
                  }
                   else
                   {
                        thisColumn = column.Bound(control.ControlType, control.ColumnName).Title(control.Description);
                            thisColumn.EditorTemplateName("MultiDropDownList");
                            thisColumn.Width(250);
                    }
 
     }
}
 
Dropdown Template
@(Html.Kendo().DropDownListFor(m => m).HtmlAttributes(new { @class = "form-control" })
    .BindTo((IEnumerable) ViewData[currentColumn + "List"])
        .DataTextField("Text")
        .DataValueField("Value")
        .ValuePrimitive(true)
 
Multiselect Template
 
@(Html.Kendo().MultiSelectFor(m => m)
                    .HtmlAttributes(new { @class = "form-control" })
 
                        .BindTo((IEnumerable)ViewData[currentColumn + "List"])
                        .DataTextField("Text")
                        .DataValueField("Value")

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 24 Aug 2015, 12:53 PM
Hello FposUser,

My assumption is that widgets DataValueField/DataTextField options are not configured correctly (the "[object Object]" text leads me to this conclusion). If this is the case, then the widgets will not be able to display the correct selected value and text and will not be able to update the Grid edited model at all.

Please verify that the DataValueField/DataTextField options points to the correct model fields (those that comes from the ViewData when widgets are bound).

Regards,
Georgi Krustev
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
FposUser
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or