Grid View for ASP.NET MVC - How to use a grid lookup control in multiple selection mode to edit grid data
This example demonstrates how to add a grid lookup control in multiple selection mode to the grid's edit form template.
The main idea is to use a column's GridViewColumn.SetEditItemTemplateContent method to add a grid lookup editor to the edit item template. In this example, the GridLookupProperties.SelectionMode property is set to Multiple
.
settings.Columns.Add(col => {
col.FieldName = "TagIDs";
col.SetEditItemTemplateContent(container => {
Html.RenderAction("GridLookupPartial", new { CurrentID = DataBinder.Eval(container.DataItem, "ID") });
});
});
@Html.DevExpress().GridLookup(settings => {
settings.Name = "TagIDs";
settings.Properties.TextFormatString = "{0}:{1}";
settings.Width = Unit.Pixel(400);
settings.GridViewProperties.CallbackRouteValues = new { Controller = "Home", Action = "GridLookupPartial", CurrentID = Model.ID };
<!-- ... -->
settings.Properties.SelectionMode = GridLookupSelectionMode.Multiple;
}).BindList(ViewData["Tags"]).Bind(Model.TagIDs).GetHtml()
To validate edit values on the client side, pass a correct model instance to the PartialView.
//HomeController.cs
public ActionResult GridLookupPartial(int? CurrentID) {
ViewData["Tags"] = DataProvider.GetTags();
GridDataItem model = new GridDataItem() { ID = -1, TagIDs = new int[0] };
if (CurrentID > -1) {
model = DataProvider.GetGridData().Where(item => item.ID == CurrentID).FirstOrDefault();
}
return PartialView(model);
}
- Grid View for ASP.NET MVC - How to use a grid lookup in single selection mode to edit grid data
- Grid View for ASP.NET Web Forms - How to use a grid lookup control in multiple selection mode to edit grid data
- Grid View for ASP.NET Web Forms - How to use a two-way data-bound grid lookup control to edit grid data
(you will be redirected to DevExpress.com to submit your response)