Use the DataKeyNames property to specify the field or fields that represent the primary key of the data source. You must set the DataKeyNames property in order for the automatic update and delete features of the GridView control to work.
a) 根据上面的引述,只有设置了 DataKeyNames 才能进行更新,但即使我没有设置 DataKeyNames,我也能够更新数据库。
b) 还是自动更新这个词还有别的意思?
谢谢
最佳答案
GridView 或 Formview 可以支持自动更新,前提是它与某种正确配置的*数据源(ObjectDataSource、SqlDataSource 等)一起使用。对于删除/更新操作,需要唯一键,因此需要 DataKeyNames 集合。例如,如果数据源是强类型数据集,它会自动开箱即用。
关于c# - 根据 Msdn GridView.DataKeyNames 必须设置,如果我们想更新数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/937197/