更改gridview,但不更改数据源
本文关键字:数据源 gridview 更改 | 更新日期: 2023-09-27 18:10:03
我有一个DataTable
, initalTable,其中包含一些初始价格。我使用这个数据表作为GridView
的DataSource
。用户可以更改GridView
中的一些值,但是initialTable中的值也被修改了。我如何绕过这个绑定?我需要在GridView
中用户更改的值与我最初存储在DataTable
中的值之间进行交叉参考。
您可以使用GetChanges方法或直接克隆DataTable。
private IEnumerable<String> GetChangedWithCrossReference()
{
return from originalRow in this.storeDataSet.PricesDataTable
join changedRow in this.storeDataSet.PricesDataTable.GetChanges(DataRowState.Changed)
on changedRow["Id"] equals originalRow["Id"]
select String.Format("Was {0}, became {1}",
originalRow ["Value"],
changedRow["Value"]);
}
或者更好更快的MSDN:
private IEnumerable<String> GetChangedWithCrossReference()
{
return from row in this.storeDataSet.PricesDataTable
select String.Format("Was {0}, became {1}",
row ["Value"],
row ["Value", DataRowState.Original])
where row.State == DataRowState.Changed;
}