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

Populating DropDownLists

Thread ID:

Created:

Updated:

Platform:

Replies:

127803 Dec 9,2016 01:11 PM UTC Dec 13,2016 10:50 AM UTC ASP.NET MVC 1
loading
Tags: Grid
Avi Segal
Asked On December 9, 2016 01:11 PM UTC

Hi,

When editing the Grid inline, how is the dropdown list data populated?

Thanks,  

Avi

Mohammed Farook J [Syncfusion]
Replied On December 13, 2016 10:50 AM UTC

Hi Avi, 
 
Thanks for contacting Syncfusion Supports. 
 
Based on your requirement, we have created a sample Grid with binding custom data source for dropdown list. Please find the code example. 
 
 
@(Html.EJ().Grid<object>("FlatGrid") 
        .Datasource((IEnumerable<object>)ViewBag.datasource) 
         
         .AllowPaging()    /*Paging Enabled*/ 
              .SelectionType(SelectionType.Single) 
              .EditSettings(edit=>{edit.AllowAdding().AllowDeleting().AllowEditing(); }) 
              .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); 
                }); 
              }) 
        .Columns(col => 
        { 
            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add(); 
            col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add(); 
            col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).EditType(EditingType.Dropdown).DataSource((List<object>)ViewData["EmployeeID"]).Width(75).Add(); 
            col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(75).Format("{0:C}").Add(); 
        })) 
 
 
The ‘DataSource’ of Columns property helps to bind the custom data source for DropDownList. 
 
 
[controller] 
 
        public ActionResult GridFeatures() 
        { 
            var DataSource = new NorthwindDataContext().OrdersViews.ToList(); 
            ViewData["EmployeeID"] = EmployeeID; 
            ViewBag.datasource = DataSource; 
            return View(); 
        } 
        public List<object> EmployeeID 
        { 
            get 
            { 
                var employeeID = new NorthwindDataContext().EmployeeViews.Select(sel => sel.EmployeeID).Distinct().ToList(); 
                var EmployeeID = new List<object>(); 
                foreach (var id in employeeID) 
                { 
                    EmployeeID.Add(new { value = id, text = id }); 
                } 
                return EmployeeID; 
            } 
        } 
    } 
 
 
 
DropDown data source must be defined as ‘value’ and ‘text’ pair. 
 
The ‘value’ property is used to data processing (key values grid) and ‘text’ is used to display text in editing view at Grid 
 
Regards, 
J.Mohammed Farook 


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

;