- Home
- Forum
- ASP.NET MVC
- Populating DropDownLists
Populating DropDownLists
Hi,
When editing the Grid inline, how is the dropdown list data populated?
Thanks,
Avi
SIGN IN To post a reply.
1 Reply
MF
Mohammed Farook J
Syncfusion Team
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
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
AS Avi Segal
- Dec 9, 2016 01:11 PM UTC
- Dec 13, 2016 10:50 AM UTC