Coder Social home page Coder Social logo

devexpress-examples / gridview-how-to-track-changes-made-with-an-unbound-checkbox-in-the-dataitemtemplate-e3979 Goto Github PK

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

Create a templated column, add a checkbox editor to the template, and save the editor's state on callbacks.

License: Other

C# 32.76% HTML 17.10% ASP.NET 0.67% Visual Basic .NET 49.46%
dotnet mvc-gridview asp-net-mvc checkbox json template

gridview-how-to-track-changes-made-with-an-unbound-checkbox-in-the-dataitemtemplate-e3979's Introduction

Grid View for ASP.NET MVC - How to track changes of a checkbox editor's state

This example demonstrates how to create a templated column, add a checkbox editor to the template, and save the editor's state on callbacks.

Save checkbox state

Overview

Call a column's SetDataItemTemplateContent method to specify a template and add a checkbox editor to the template. Specify the editor's Name property based on the row's key value.

@Html.DevExpress().GridView(settings => {
    settings.Name = "gvTypedListDataBinding";
    settings.CallbackRouteValues = new { Controller = "Home", Action = "TypedListDataBindingPartial" };
    settings.KeyFieldName = "ID";
    settings.Columns.Add(column => {
        column.SetDataItemTemplateContent(c => {
            Html.DevExpress().CheckBox(checkboxSettings => {
                checkboxSettings.Name = "cb_" + c.KeyValue.ToString();
                checkboxSettings.Properties.ClientSideEvents.CheckedChanged = "OnCheckedChanged";
                if(ViewData["items"] != null) {
                    Dictionary<string, bool> items = (Dictionary<string, bool>)ViewData["items"];
                    checkboxSettings.Checked = items.ContainsKey(checkboxSettings.Name) && (bool)items[checkboxSettings.Name];
                }              
            }).Render();
        });
    });
    settings.ClientSideEvents.BeginCallback = "OnBeginCallback";
}).Bind(Model).GetHtml()

Handle the editor's client-side CheckedChanged event and use a custom JS object to store the checked editor's key value. When the grid sends a callback to the server, the JS object is serialized and passed to the Controller as a custom parameter. Then this object is deserialized on the View side to restore the editor's state.

Files to Review

Documentation

gridview-how-to-track-changes-made-with-an-unbound-checkbox-in-the-dataitemtemplate-e3979's People

Contributors

devexpressexamplebot avatar elenapeskova avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

elenapeskova

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.