Skip to content

Add a grid lookup control in single selection mode to the grid's edit form template.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/asp-net-mvc-grid-use-grid-lookup-in-single-selection-mode-to-edit-data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Grid Lookup in single selection mode

Overview

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 });
}

Files to Review

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)