Hi Varde,
Glad to hear from you.
Now I've got your actual concern based on the further description. The
problem you encounter is due to the gridview's editing/updating rely on the
RowIndex rather than the data column fields(primary key or other columns).
Actually, this problem may also occur when you perform edit in GridView and
the Rows are displayed based on sorting of some certain columns in the
resultset.
So far, the best solution to address such issue is always make sure that
you use the primary key to identify the record that will be edited. And for
ASP.NET , you can use an additional DetailsView/FormView control to edit
the detailed info of a certain record. And it is very easy to associate the
DetailsView/FormView with the Gridview control's current Row. The following
tutorial also introducing this:
#Master/Detail Using a Selectable Master GridView with a Details DetailView
http://www.asp.net/learn/data-access/tutorial-10-cs.aspx
Thus, in the detailsView/FormView, you are confident that the row is the
correct one(as it is bound via primary key selection from database).
Hope this helps.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#noti f
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Thread-Topic: Concurrency issue
Subject: RE: Concurrency issue
Date: Wed, 2 Jul 2008 10:00:02 -0700
Hello Steven,
I reviewed the three articles you referenced and have implemented optimistic
concurrency in my web app as it was described in the “Implementing Optimistic
Concurrency�article. If I place a record in edit mode, then have another
user modify the record and update, and then modify the record myself and
attempt to update I can raise the DBConcurrencyException in the RowUpdated
event of the gridview. I also noticed the following in this article:
“Optimistic concurrency control works by ensuring that the record being
updated or deleted has the same values as it did when the updating or
deleting process started. For example, when clicking the Edit button in an
editable GridView, the record's values are read from the database and
displayed in TextBoxes and other Web controls. These original values are
saved by the GridView. Later, after the user makes her changes and clicks the
Update button, the original values plus the new values are sent to the
Business Logic Layer, and then down to the Data Access Layer. The Data Access
Layer must issue a SQL statement that will only update the record if the
original values that the user started editing are identical to the values
still in the database.�
Based on my original example I think the following is occurring.
1] My gridview currently contains the following records selected from a table
Gridview Index | ID (Primary Key) | Name
0 | 200 | Jones
1 | 300 | Peters
2 | 400 | Andrews
2] “Another user�inserts a new record into the table with an ID of
100
and
Name equal to Walters and commits
3] I click the Edit button for record � | 200 | Jones�
4] A postback occurs and the records are reread from the database (now the
original values) and placed in the gridview as follows
Gridview Index | ID (Primary Key) | Name
0 | 100 | Walters
1 | 200 | Jones
2 | 300 | Peters
3 | 400 | Andrews
Notice that the new record now has a gridview index of 0, and the one
that
I
clicked on to edit now has a gridview index of 1.
5] � | 100 | Walters�(the wrong record) is placed in edit mode. I can
modify this record and update without raising an exception because the
original values have not changed since they were reread from the database.
I am wondering how can you ensure the correct record is placed in edit mode
regardless of records inserted or deleted by other users between the time
that I initially loaded the page and when I click edit on the record I want
to modify? Thanks for your help.
: