S
Stamen Gortchev
Hi all,
I think there is an inherent problem with most examples on the internet
(with MSDN, too!) showing datagrid's databinding. Here is, how they look
like:
========================
On Page_Load
if !IsPostBack: BindGrid()
On_Edit
Set datagrid's EditItem to clicked item
BindGrid
void BindGrid()
Fill DataSet through dataadapter
DataGrid.DataBind()
========================
Imagine a simple table "Names" with two columns: NameID and Name
Your SQL Select Statement reads "SELECT NameID, Name FROM Names ORDER BY
Name" and you have two records in it:
ID=1, Name = "aaaa"
ID=2, Name = "cccc"
So, the first time you call the page, you get following grid:
1 "aaaa" edit-button
2 "cccc" edit-button
during the time in which you are viewing this html page on your IE someone
inserts another record in the table: "ID=3, Name='bbbb'".
Then you click the edit button of the second row into your grid (2
"cccc") intending to edit the name "cccc". When you klick the edit button,
however, you get following grid:
1 "aaaa" edit-button
3 [bbbb] - updatable!!! Update-button, cancel-button
2 "cccc" edit-button
I am sure, you ghet what the reason is. What is the best solution to guard
against this problem?
Thank you for taking your time and understanding what I mean. I thought of a
logical solution which however does not work. In case a discussion occur, I
will write about it.
All best
Stamen
I think there is an inherent problem with most examples on the internet
(with MSDN, too!) showing datagrid's databinding. Here is, how they look
like:
========================
On Page_Load
if !IsPostBack: BindGrid()
On_Edit
Set datagrid's EditItem to clicked item
BindGrid
void BindGrid()
Fill DataSet through dataadapter
DataGrid.DataBind()
========================
Imagine a simple table "Names" with two columns: NameID and Name
Your SQL Select Statement reads "SELECT NameID, Name FROM Names ORDER BY
Name" and you have two records in it:
ID=1, Name = "aaaa"
ID=2, Name = "cccc"
So, the first time you call the page, you get following grid:
1 "aaaa" edit-button
2 "cccc" edit-button
during the time in which you are viewing this html page on your IE someone
inserts another record in the table: "ID=3, Name='bbbb'".
Then you click the edit button of the second row into your grid (2
"cccc") intending to edit the name "cccc". When you klick the edit button,
however, you get following grid:
1 "aaaa" edit-button
3 [bbbb] - updatable!!! Update-button, cancel-button
2 "cccc" edit-button
I am sure, you ghet what the reason is. What is the best solution to guard
against this problem?
Thank you for taking your time and understanding what I mean. I thought of a
logical solution which however does not work. In case a discussion occur, I
will write about it.
All best
Stamen