This is a migrated thread and some comments may be shown as answers.

"Refresh" GridView After Pressing Cancel Button

4 Answers 507 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 20 Nov 2015, 01:20 AM

 Hi,

 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?

 

 Thanks,

Matthew

4 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 20 Nov 2015, 01:40 PM
Hello Matthew,

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.
 
Regards,
Dess
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Matthew
Top achievements
Rank 1
answered on 20 Nov 2015, 04:02 PM

Hi Dess,

 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:

 

private void btnCancel_Click(object sender, EventArgs e)
{
    btnCancel.Visible = false;
    btnSave.Visible = false;
    btnAdd.Visible = true;
    btnEdit.Visible = true;
 
    foreach (int x in updatedRows)
    {
        mainGrid.Rows[x].InvalidateRow();
    }
 
    updatedRows.Clear();
}

 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? 

 

Thanks,

Matthew

 

 

 

 

0
Matthew
Top achievements
Rank 1
answered on 20 Nov 2015, 09:41 PM

What ended up working was reassigning my gridview datasource like so:

 

mainGrid.DataSource = vendorsTableAdapter.GetData();

 

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.

 

Kind Regards,

Matthew

 

 

0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 Nov 2015, 12:13 PM
Hello Matthew,

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.

Regards,
Dess
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Matthew
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Matthew
Top achievements
Rank 1
Share this question
or