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. Image for the cookie policy date

Grid Dropdownlist not displaying current value upon editing

Hello,
Currently experiencing the following issue: When my grid loads, all dropdowns show the correct value as passed to them by their datasource. However, when I click to edit a row, the dropdown will blank out and not show any selected option. The dropdownlist of a certain row that is being edited should default to the current value in the datasource. Code and screenshots below:

Grid control:

@(Html.EJ().Grid<IEnumerable<RecipeManager.ViewModels.UsersAndRoles>>("AdminGrid")
          .Datasource(Model.UsernamesAndRoles)
          .AllowSorting()
          .AllowPaging()
          .ToolbarSettings(x =>
          {
              x.ShowToolbar()
              .ToolbarItems(y =>
              {
                  y.AddTool(ToolBarItems.Search);
                  y.AddTool(ToolBarItems.Add);
                  y.AddTool(ToolBarItems.Edit);
                  y.AddTool(ToolBarItems.Delete);
                  y.AddTool(ToolBarItems.Update);
                  y.AddTool(ToolBarItems.Cancel);
              });
          })
          .EditSettings(x => { x.AllowAdding().AllowDeleting().AllowEditing(); })
          .ClientSideEvents(e => e.ToolbarClick("toolbarClicked"))
          .ClientSideEvents(e => e.ActionBegin("actionBegin"))
          .Columns(col =>
          {
              col.Field("RowNumber").HeaderText("Row Number").Width(75).IsPrimaryKey(true).AllowEditing(true).Add();
              col.Field("Username").HeaderText("User Name").Width(75).Add();
              col.Field("Role").HeaderText("Role").Width(80).EditType(EditingType.Dropdown).DataSource(Model.RoleOptions).Add();
          }))


In the attached zip file, please see before.png for a screenshot of the grid after page load. See after.png for a screenshot immediately after clicking "edit" on a row. 


Attachment: dropdownIssue_150e534.zip

1 Reply

PK Prasanna Kumar Viswanathan Syncfusion Team October 24, 2016 06:56 AM UTC

Hi Greg, 

Thanks for contacting Syncfusion support. 

We suspect that you have not binded the dataSource for the dropdownlist in text and value format. To avoid the mentioned issue, the datasource binded for the dropdown list must be passed in the value and text format. 

Find the code example and sample: 


@(Html.EJ().Grid<Sample118577.OrdersView>("FlatGrid") 
.Datasource(Model) 
.-------------------------------------------- 
.Columns(col => 
{ 
    ------------------------ 
    col.Field("EmployeeID").HeaderText("Employee Name").EditType(EditingType.Dropdown).TextAlign(TextAlign.Left).DataSource((List<object>)ViewData["EmployeeID"]).Width(90).Add(); 
    ------------------------ 
}) 
) 

-------------------------------------------------------- 

public ActionResult GridFeatures(string id) 
        { 
            -------- 
            ViewData["EmployeeID"] = EmployeeID; 
            ---- 
        } 
       
        public List<object> EmployeeID 
        { 
            get 
            { 
                var employeeID = db.OrdersViews.Select(s => s.EmployeeID).Distinct().ToList(); 
                var EmployeeID = new List<object>(); 
                foreach (var id in employeeID) 
                { 
                    EmployeeID.Add(new { value = id, text = id }); 
                } 
                return EmployeeID; 
            } 
        } 


Regards, 
Prasanna Kumar N.S.V 
 


Loader.
Live Chat Icon For mobile
Up arrow icon