C# GridView 删除不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13524/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-01 08:45:50  来源:igfitidea点击:

GridView delete not working

提问by Guy

I'm using a GridViewin C#.NET 3.5 and have just converted the underlying DataSourcefrom Adaptermodel to an object which gets its data from LINQ to SQL - i.e. a Business object that returnsa List<>for the GetData()function etc.

我使用的是GridView在C#.NET 3.5和刚转换的基本DataSourceAdapter模型到对象从LINQ中获取数据到SQL -即业务对象是returns一个List<>GetData()等功能

All was well in Denmark and the Update, and conditional Selectstatements work as expected but I can't get the Deletefunction to work. Just trying to pass in the ID or the entire object but it's being passed in a "new"object with none of the properties set. I'm just wondering if it's the old OldValuesParameterFormatString="original_{0}"monster in the ObjectDataSourcecausing confusion again.

在丹麦一切顺利,Update, 和条件Select语句按预期工作,但我无法使该Delete功能正常工作。只是试图传入 ID 或整个对象,但它被传入一个没有设置任何属性的“新”对象。我只是想知道是否是再次引起混乱的老OldValuesParameterFormatString="original_{0}"怪物ObjectDataSource

Anybody have any ideas?

有人有任何想法吗?

回答by Guy

I found the solution. I had to set the GridView's DataKeyNames property to the unique key that my data was returning (in this case a classically named ID field). I'm guessing that this property "unset" itself when the Grid refreshed.

我找到了解决方案。我必须将 GridView 的 DataKeyNames 属性设置为我的数据返回的唯一键(在本例中为经典命名的 ID 字段)。我猜这个属性在 Grid 刷新时会“取消设置”。