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.
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);
}
- Default.aspx (VB: Default.aspx)
- Default1.aspx (VB: Default1.aspx)
- Default1.aspx.cs (VB: Default1.aspx.vb)
- Default2.aspx (VB: Default2.aspx)
- Default2.aspx.cs (VB: Default2.aspx.vb)
- Grid View for ASP.NET Web Forms - How to use template editors to update grid data
- Grid View for ASP.NET Web Forms - Implement the multi-row edit functionality in a dynamically bound multi-page grid
(you will be redirected to DevExpress.com to submit your response)