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
close icon

Drop Down List

Hi Support

Could you show me how to populate Drop down List in a Grid field using a table from EF

Regards

Edmund Herbert

1 Reply

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team August 3, 2017 05:48 PM UTC

Hi Edmund, 

Thanks for contacting Syncfusion Support. 

We have created sample with Entity framework by creating the db NorthWNDContext_context and bind to the Grid datasource. Also we have bind the Employee db to the dropdown datasource of the Grid column.Please refer to the code example:- 

<ej-grid id="Grid" allow-paging="true" allow-sorting="true" action-complete="onComplete"> 
      <e-datamanager json="(IEnumerable<Orders>)ViewBag.datasource" remove-url="Home/Delete" update-url="Home/Update" insert-url="Home/Insert" adaptor="remoteSaveAdaptor"></e-datamanager> 
                <e-edit-settings allow-adding="true" allow-editing="true" allow-deleting="true" ></e-edit-settings> 
                <e-columns> 
                    <e-column field="OrderID" is-primary-key="true" header-text="Order ID" text-align="Right"></e-column> 
                    <e-column field="CustomerID" header-text="CustomerID" edit-type="String"></e-column> 
                    <e-column field="ShipCity" header-text="Ship City datasource="(IEnumerable<Employee>)ViewBag.datasource"  edit-type="Dropdown"></e-column> 
                </e-columns> 
             
    </ej-grid> 

Serverside:- 

public class HomeController : Controller 
    { 
        private NORTHWNDContext _context; 
        public HomeController(NORTHWNDContext context) 
        { 
            _context = context; 
        } 
 
        public IActionResult Index() 
        { 
 
            List<Orders>  Result = _context.Orders.Take(100).ToList(); 
            ViewBag.datasource = Result; 
                            List<Employee> data = new List<Employee>(); 
            data = db.Employees.ToList(); 
            ViewBag.DataSource = data; 
            return View(); 
          } 
                   } 
        public List<Orders> GetData() 
        { 
 
            List<Orders> datas = _context.Orders.Take(100).ToList(); 
            return datas; 
        } 
                   
      public ActionResult Data([FromBody]DataManager dm) 
        { 
            IEnumerable Data = _context.Orders.Take(100).ToList(); 
 
            Syncfusion.JavaScript.DataSources.DataOperations operation = new Syncfusion.JavaScript.DataSources.DataOperations(); 
            if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting 
            { 
                Data = operation.PerformSorting(Data, dm.Sorted); 
            } 
            if (dm.Where != null && dm.Where.Count > 0) //Filtering 
            { 
                Data = operation.PerformWhereFilter(Data, dm.Where, dm.Where[0].Operator); 
            } 
            if (dm.Search != null && dm.Search.Count > 0) //searching 
            { 
                Data = operation.PerformSearching(Data, dm.Search); 
            } 
 
            int count = Data.AsQueryable().Count(); 
            if (dm.Skip != 0) 
            { 
                Data = operation.PerformSkip(Data, dm.Skip); 
            } 
            if (dm.Take != 0) 
            { 
                Data = operation.PerformTake(Data, dm.Take); 
            } 
            return Json(new { result = Data, count = count }); 
         
    } 
        public class DataResult 
        { 
            public IEnumerable result { get; set; } 
            public int count { get; set; } 
            public IEnumerable aggregate { get; set; } 
            public IEnumerable groupDs { get; set; } 
        } 
 
        public ActionResult CellEditInsert([FromBody]EditParams value) 
        { 
            var datas = _context; 
            datas.Orders.Add(value.value); 
            datas.SaveChanges(); 
            return Json(value); 
        } 
        public ActionResult CellEditUpdate([FromBody]EditParams value) 
        { 
            var db = _context; 
            db.Entry(value.value).State = EntityState.Modified; 
            db.SaveChanges(); 
            return Json(value); 
 
        } 
        public ActionResult CellEditDelete([FromBody]EditParams value) 
        { 
            var db = _context; 
            Orders order = db.Orders.Where(c => c.OrderID == Convert.ToInt32(value.key)).FirstOrDefault(); 
            db.Orders.Remove(order); 
            db.SaveChanges(); 
            return Json(order); 
        } 


Please refer to the sample and documentation link :- 



Regards, 

Farveen sulthana T 


Loader.
Live Chat Icon For mobile
Up arrow icon