GridviewYou can save the original value and the new value of each data column at the same time, so you can handle concurrency conflicts.
<%@ Page Language= "C #" %>
<!Doctype Html Public "-// W3C // dtd xhtml 1.1 // en" Http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd>
<Html Xmlns= "Http://www.w3.org/1999/xhtml" >
<Head ID= "Head1" Runat= "Server">
<Title>Concurrency</Title>
</Head>
<Body>
<Form ID= "Form1" Runat= "Server">
<Div>
<ASP:Gridview
ID= "Grdmovies"
Performanceid= "Srcmovies"
Datakeynames= "ID"
Autogenerateeditbutton= "True"
Runat= "Server" />
<ASP:Sqldatasource
ID= "Srcmovies"
Conflictdetection= "Compareallvalues"
Oldvaluesparameterformatstring= "Original _ {0 }"
Connectionstring="<%$ Connectionstrings: Movies%>"
Selectcommand= "Select ID, title, Director from movies"
Updatecommand= "Update movies set Title = @ title, Director = @ Director
Where id = @ original_id and Title = @ original_title and Director = @ original_director"
Runat= "Server" />
</Div>
</Form>
</Body>
</Html>
AboveCodeIn the list,SqldatasourceControlConflicatdetectionAttributes andOldvaluesparameterformatstringAttribute values are assigned.SqldatasourceControl to keep the original value and modified value of this column for each data column.
ConflicatdetectionThe attribute can be one of the following two values:
Compareallvalues
Overwritechanges
ConflicatdetectionThe default value isOverwritechanges, This will causeSqldatasourceThe control directly overwrites the data column with the new value. IfCompareallvalues,SqldatasourceThe control retains the original value and modified value for each column.
OldvaluesparameterformatstringAttribute is used to provide a unique name for the column's original value. For example,SqldatasourceControlUpdatecommandThe attribute values are as follows:
Updatecommand= "Update movies set Title = @ title, Director = @ Director
Where id = @ original_id and Title = @ original_title and Director = @ original_director"
@ Original_id, @ Original_title, @ original_director parameter indicates the original values of these columns. If you modify these records first, this modification is ignored.