Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

ASPxGridView - How to implement instant editing with check boxes in columns

$
0
0

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

Question Comments

Added By: Robert Kosko 1 at: 4/23/2014 7:41:42 AM    

Just to let everyone know. If you have problems with this code, especially the NamingContainer code listed above, YOU MUST upgrade to v2013. I was using the old 2012 version and the NamingContainer returned the webpage instead of the grid. Upon the upgrade, everything ran fine.

Added By: naresh kumar @Sonata at: 4/17/2015 8:31:09 AM    

Then on click of button save, how can i get the state of the checkboxes that were selected.  provide me the sample code for BtnSave click.

Added By: Alessandro (DevExpress Support) at: 4/17/2015 9:55:25 AM    Hi,

We will answer this question in the context of the T231555: ASPxGridView - Check box state in the DataItemTemplate is lost ticket. Thank you for your time and cooperation in advance.

Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>