- Home
- Forum
- ASP.NET MVC
- DropDown selected item show value instead of text
DropDown selected item show value instead of text
When i select something from DropDownList from Grid, instead of displaying the text of the selected element it is displayed the value of element.
here is my code
@(Html.EJ().Grid<Category>("CalendarItemCategories")
.Datasource(Model)
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); })
.ClientSideEvents(eve => { eve.EndEdit("endEdit").EndAdd("endAdd").EndDelete("endDelete"); })
.ToolbarSettings(toolbar =>
{
toolbar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.Add);
items.AddTool(ToolBarItems.Edit);
items.AddTool(ToolBarItems.Delete);
items.AddTool(ToolBarItems.Update);
items.AddTool(ToolBarItems.Cancel);
});
})
.AllowSorting()
.AllowFiltering()
.AllowPaging()
.PageSettings(page => page.PageSize(20))
.ClientSideEvents(ev => ev.RowDataBound("rowdatabound"))
.IsResponsive()
.Columns(col =>
{
col.Field(c => c.Id).HeaderText("Id").IsPrimaryKey(true).Visible(false).Add();
col.Field(c => c.Color).HeaderText(FormsResources.Color).EditTemplate(edit => { edit.Create("create").Read("read").Write("write"); }).Width(90).Priority(1).Add();
col.Field(c => c.FontColor).HeaderText("FontColor").EditTemplate(edit => { edit.Create("createFontColor").Read("readFontColor").Write("writeFontColor"); }).Width(90).Priority(1).Add();
col.Field(c => c.Description).HeaderText(FormsResources.Description).Priority(2).Add();
col.Field(c => c.Form.Title).HeaderText(FormsResources.AssociatedForm).DataSource(ViewBag.Forms).EditType(EditingType.DropdownEdit).Priority(3).Add();
}))
SIGN IN To post a reply.
3 Replies
FS
Farveen Sulthana Thameeztheen Basha
Syncfusion Team
October 1, 2019 04:49 AM UTC
Hi PaoloConstantin,
Thanks for contacting Syncfusion Support.
Query#:- When i select something from DropDownList from Grid, instead of displaying the text of the selected element it is displayed the value of element.
When we bind dropdown dataSource in the form of text and value pair for Grid column, by default it will save the record by displaying values in the dropdownList. Instead, if you want to save the records with text to display on Grid, we suggest you to use ForeignKey column Feature of the Grid. Data Field and Text can be set using ForeignKeyField and ForeignKeyValue property of Columns.
Refer to the code example:-
|
@(Html.EJ().Grid<OrdersView>("ForeignKey")
.Datasource((IEnumerable<object>)ViewBag.dataSource1)
.AllowPaging()
.AllowGrouping()
.Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width(90).Add();
col.Field("EmployeeID").HeaderText("Employee Name").ForeignKeyField("EmployeeID")
.ForeignKeyValue("FirstName").DataSource((IEnumerable<object>)ViewBag.dataSource2)
.TextAlign(TextAlign.Left).Width(90).Add();
})
)
} |
Please refer to the documentation and Demo Link:-
Otherwise you can mentioned the text and value pair value as same in DropDownEditOptions as like below code example:-
|
@(Html.EJ().Grid<object>("FlatGrid")
.AllowSorting()
.Columns(col =>
{
. . .
col.Field("EmployeeID_FirstName").HeaderText("First Name")
.EditType(EditingType.Dropdown).DataSource((IEnumerable<object>)ViewBag.datasource2).DropDownEditOptions(new DropDownListProperties() { DropDownListFields = { Text = "FirstName", Value = "FirstName" } }).Width(90).Add();
})
)
|
Please get back to us if you need any further assistance.
Regards,
Farveen sulthana T
PA
PaoloConstantin
October 1, 2019 07:20 AM UTC
Thanks for help, it works for me
FS
Farveen Sulthana Thameeztheen Basha
Syncfusion Team
October 2, 2019 05:09 AM UTC
Hi PaoloConstantin,
Thanks for your update. Please get back to us if you need any further assistance.
Regards,
Farveen sulthana T
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
PA PaoloConstantin
- Sep 30, 2019 02:58 PM UTC
- Oct 2, 2019 05:09 AM UTC