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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Grid Dropdownlist not displaying current value upon editing

Thread ID:

Created:

Updated:

Platform:

Replies:

127031 Oct 21,2016 04:10 PM UTC Oct 24,2016 06:56 AM UTC ASP.NET MVC 1
loading
Tags: Grid
Greg Hofman
Asked On October 21, 2016 04:10 PM UTC

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

Prasanna Kumar Viswanathan [Syncfusion]
Replied On 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 
 


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.

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

;