I have a gridview that is bound to a SQL Server DB table. Users of the gridview can perform inline editing and save their changes using a save button. The issue I am having is when a user makes changes to a row or rows and then presses a cancel button. How do I reset these rows back to their initial values when a cancel button is clicked. Is their a way to refresh or rebind the gridview?
4 Answers, 1 is accepted
Thank you for writing.
In order to refresh the entire grid, you can use the RadGridView.MasterTemplate.Refresh method. However, you can refresh a certain row by calling the InvalidateRow method for the affected GridViewRowInfo.
I hope this information helps. Should you have further questions I would be glad to help.
Thanks for your response. I tried both the RadGridView.MasterTemplate.Refresh method and the InvalidateRow method and didn't have success with either one.
Below is the code from my cancel button click event method:
updatedRows is simply a list of the row indexes that have been modified. If the user presses cancel, I want these modified rows to be invalidated and their values to revert back to what is stored in the DB.
I've also attached a screenshot of the binding source that the grid datasource was set to. I originally set this grid datasource using the 'Add project data source' wizard. Again, this is a direct connection to a 'vendors' SQL Server DB table. Am I missing something here?
What ended up working was reassigning my gridview datasource like so:
It would still be useful for myself (and probably others) to understand why using the InvalidateRow method didn't work as expected. Any guidance you guys can offer would be wonderful.
Thank you for writing back.
The provided explanation is greatly appreciated. When you edit a cell, this value is stored in the grid. However, the database is still not updated. Refreshing the row/ master template will invalidate the rows, but the cell values will not be reverted back as it is data information, not style. That is why it is necessary to set the DataSource property again as you have already found out. Thus, RadGridView will load the records from the database with the desired values.
I hope this information helps. If you have any additional questions, please let me know.