Hey,
I am having a problem updating a datatable that is bound to a datagrid. Tried a bunch of approaches but the problem is t*he underlying datatable reverts back to its initial state* everytime u click a command.
Here's the example code:
On Label Click:
protected void OnUserDataGridCommand(object source, DataGridCommandEventArgs e)
{
DataTable dt = DataGridUsers.DataSource as DataTable;
if (e.CommandName == "Lock Out")
{
// Approach 1
e.Item.Cells[0].Text = "Lock";
DataGridUsers.DataSource = dt;
DataGridUsers.DataBind();
// Approach 2
dt.Rows[e.Item.ItemIndex]["FirstName"] = "LOCK";
dt.Rows[e.Item.ItemIndex].AcceptChanges();
DataGridUsers.DataSource = dt;
DataGridUsers.DataBind();
}
}
So this will update the row's first name to say Lock but when you click on another row the previously Locked will revert to the first name. When I breakpoint regardless of a row displaying lock, the datatable always is the initial data (no "LOCK" data).