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
GridView delete not working
提问by Guy
I'm using a GridView
in C#.NET 3.5 and have just converted the underlying DataSource
from Adapter
model to an object which gets its data from LINQ to SQL - i.e. a Business object that returns
a List<>
for the GetData()
function etc.
我使用的是GridView
在C#.NET 3.5和刚转换的基本DataSource
从Adapter
模型到对象从LINQ中获取数据到SQL -即业务对象是returns
一个List<>
对GetData()
等功能
All was well in Denmark and the Update
, and conditional Select
statements work as expected but I can't get the Delete
function 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 ObjectDataSource
causing 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 刷新时会“取消设置”。