This is a bit of a hypothetical question that sent me down a garden path ... Let's say I have a gridview that I would like to edit ... using a method that links the data.
private void BindGridFirst() { var data = new List<string>() { "A","B","C","D","E","F" }; gridView.DataSource = data; gridView.DataBind(); }
Now suppose I look at this page and another user comes in and makes some changes to the base data, and now I go to the edit button and edit D ..
The editing method is quite simple:
protected void RowEdit(object sender, GridViewEditEventArgs e) { gridView.EditIndex = e.NewEditIndex; BindGridSecond(); }
Edit: I feel compelled to indicate that this method is used in almost all online examples, including Microsoft.
This BindGridSecond () method looks like this:
private void BindGridSecond() { var data = new List<string>() { "A", "AA", "B","C","D","E","F" }; gridView.DataSource = data; gridView.DataBind(); }
This is exactly the same, but the data is now changed. After updating the user interface, the user is now in edit mode on line C.
Not what the user expected or wanted. How should this scenario be handled to avoid such a problem?