Grid View for ASP.NET MVC - How to use a grid lookup control in single selection mode to edit grid data
This example demonstrates how to add a grid lookup control in single 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 Single
.
column.SetEditItemTemplateContent(container => {
Html.RenderAction("GridLookupPartial", new { CurrentCategory = DataBinder.Eval(container.DataItem, "CategoryID") });
});
@Html.DevExpress().GridLookup(settings => {
settings.Name = "CategoryID";
settings.Width = Unit.Percentage(100);
settings.GridViewProperties.CallbackRouteValues = new { Controller = "Home", Action = "GridLookupPartial", CurrentCategory = Model.CategoryID };
<!-- ... -->
settings.Properties.SelectionMode = GridLookupSelectionMode.Single;
}).BindList(ViewData["Categories"]).Bind(Model.CategoryID).GetHtml()
To validate edit values on the client side, pass a correct model instance to the PartialView.
// HomeController.cs
public ActionResult GridLookupPartial(int? CurrentCategory) {
ViewData["Categories"] = context.Categories;
if (CurrentCategory == null)
CurrentCategory = -1;
return PartialView(new Product() { CategoryID = (int)CurrentCategory });
}
- Grid View for ASP.NET MVC - 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 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)