We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

DropDown selected item show value instead of text

Thread ID:

Created:

Updated:

Platform:

Replies:

147980 Sep 30,2019 02:58 PM UTC Oct 2,2019 05:09 AM UTC ASP.NET MVC 3
loading
Tags: Grid
PaoloConstantin
Asked On September 30, 2019 02:58 PM UTC

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();
              }))


Farveen Sulthana Thameeztheen Basha [Syncfusion]
Replied On 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 



PaoloConstantin
Replied On October 1, 2019 07:20 AM UTC


Thanks for help, it works for me

Farveen Sulthana Thameeztheen Basha [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon