This example illustrates how to implement instant editing in ASPxGridView. It is divided in two independent samples:
- The first sample (the Default1 page) illustrates how to post modified data to the underlying database on demand. Note that starting with v2013 vol 2, we provide a similar feature out-of-the-box: Batch Edit Mode.
- The second sample (the Default2 page) illustrates how to post modified data to the underlying database immediately.
In both samples, we define a custom GridViewDataColumn.DataItemTemplate with ASPxCheckBox. We handle the ASPxCheckBox' Init event (see The general technique of using the Init/Load event handler) to generate client-side ASPxClientCheckBox.CheckedChanged Event handler dynamically based on the current filed name and row key:
[C#]// Default1.aspx.csprotectedvoidcb_Init(objectsender,EventArgse){ASPxCheckBoxcheckBox=(ASPxCheckBox)sender;GridViewDataItemTemplateContainercontainer=(GridViewDataItemTemplateContainer)checkBox.NamingContainer;stringkey=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.csprotectedvoidcb_Init(objectsender,EventArgse){ASPxCheckBoxcheckBox=(ASPxCheckBox)sender;GridViewDataItemTemplateContainercontainer=(GridViewDataItemTemplateContainer)checkBox.NamingContainer;stringkey=string.Format("{0}|{1}",container.Column.FieldName,container.KeyValue);checkBox.ClientSideEvents.CheckedChanged=string.Format("function(s, e) {{ grid.PerformCallback('{0}|' + s.GetChecked()); }}",key);}
As you can see, in the first case we just save the modified value to the hidden field via the ASPxClientHiddenField.Set Method. These values will be extracted from it and posted to the database later when the "Save Changes" button is clicked. In the second case, we immediately initiate a saving callback via the ASPxClientGridView.PerformCallback Method.
See Also:
How to perform ASPxGridView instant updating using different editors in the DataItem template
How to implement the multi-edit functionality with a multi-page grid that is bound dynamically