Skip to content

Create templated columns, add checkbox editors to the templates, and configure the grid's cell edit functionality.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/asp-net-web-forms-grid-edit-data-in-grid-with-template-checkboxes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid View for ASP.NET Web Forms - How to edit data in the grid with template checkboxes

This example demonstrates how to create templated columns, add checkbox editors to the templates, and configure the grid's cell edit functionality. The following approaches are available:

  • Save modified data to a hidden field and pass it in batches to the server on a button click. Note that starting with v13.2, this functionality is available out-of-the-box: Grid in Batch Edit Mode.
  • Pass modified cell values to the server immediately after changing.

Overview

Specify a column's DataItemTemplate property and add a checkbox to the template. In the checkbox's server-side Init event, dynamically get the current column's field name and the row's key value and pass these values to the checkbox's client-side CheckedChanged event.

For the first approach, save modified values to a hidden field - call the hidden field's Set method. These values are saved to the data source after a user clicks the Save Changes button.

For the second approach, call the grid's client-side PerformCallback method immediately after a user changes a checkbox's value and pass this value to the server to save it to the data source.

// Default1.aspx.cs
protected void cb_Init(object sender, EventArgs e) {
    ASPxCheckBox checkBox = (ASPxCheckBox)sender;
    GridViewDataItemTemplateContainer container = (GridViewDataItemTemplateContainer)checkBox.NamingContainer;

    string key = string.Format("{0}_{1}", container.Column.FieldName, container.KeyValue);
    checkBox.ClientSideEvents.CheckedChanged = string.Format("function(s, e) {{ hf.Set('{0}', s.GetChecked()); }}", key);
}

// Default2.aspx.cs
protected void cb_Init(object sender, EventArgs e) {
    ASPxCheckBox checkBox = (ASPxCheckBox)sender;
    GridViewDataItemTemplateContainer container = (GridViewDataItemTemplateContainer)checkBox.NamingContainer;

    string key = string.Format("{0}|{1}", container.Column.FieldName, container.KeyValue);
    checkBox.ClientSideEvents.CheckedChanged = string.Format("function(s, e) {{ grid.PerformCallback('{0}|' + s.GetChecked()); }}", key);
}

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

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

About

Create templated columns, add checkbox editors to the templates, and configure the grid's cell edit functionality.

Topics

Resources

License

Stars

Watchers

Forks