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

New Combobox items blank in Grid

1 Answer 25 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gary
Top achievements
Rank 1
Gary asked on 20 Feb 2014, 10:40 PM
I have a grid with a ComboBox:

[...]
.Columns(c=> {
     c.ForeignKey(o => o.Item, (IEnumerable<MyIdValueClass>)ViewBag.FK_Items, "Id", "Value").EditorTemplateName("ComboBox");
[...]

public class MyIdValueClass
  {
    public string Id { get; set; }
    public string Value { get; set; }
  }

Template Code:
@(Html.Kendo().ComboBox()
    .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(""))
    .BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"])
)


Whenever I type in a new entry (not selected from the dropdown) and click Update, the entry is saved into the database properly, but it shows up blank in the Grid.  If you subsequently click Edit, the value appears so that you can edit it.  Click Update or Cancel and it is still blank.  Only after refreshing the page will the value show up properly.  Entries selected from the dropdown list display properly.  How can I get the typed entries to display properly?

Thanks in advance,
Gary

1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 24 Feb 2014, 03:00 PM
Hello Gary,

This behavior is expected, because when you create a new item in the ComboBox it has no Id and does not exist in the columns.values array. Although not supported out of the box, you can use the Value for both dataTextField and dataValueField and a ClientTemplate to display the current Value as a workaround. For example:  
c.ForeignKey(o => o.Item, (IEnumerable<MyIdValueClass>)ViewBag.FK_Items, "Value", "Value").EditorTemplateName("ComboBox").ClientTemplate("#=Value#");

Regards,
Alexander Popov
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
Gary
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Share this question
or