Coder Social home page Coder Social logo

devexpress-examples / gridview-how-to-use-gridlookup-in-editform-in-multiple-selection-mode-t328613 Goto Github PK

View Code? Open in Web Editor NEW
0.0 55.0 1.0 320 KB

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

License: Other

C# 37.36% HTML 14.55% ASP.NET 0.47% Visual Basic .NET 47.62%
dotnet mvc-gridview asp-net-mvc editors selection template

gridview-how-to-use-gridlookup-in-editform-in-multiple-selection-mode-t328613's Introduction

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.

Grid Lookup in multiple 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 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);
}

Files to Review

Documentation

More Examples

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.