当我尝试在 ASP.NET 中更新我的 gridview 时出现异常
当我尝试更新使用
连接的 gridview 并在此数据源中启用更新和删除时,我收到一个异常告诉我:
javaScript 运行时错误: Sys.WebForms.PageRequestManagerServerErrorException:找不到 与存储在的原始值中的给定键匹配的行 视图状态。确保“keys”字典包含唯一的键 与上一个 Select 返回的行对应的值 操作。
我该如何解决这个异常?
when I tried to update my gridview which is connected using <asp:LinqDataSource>
and Enabling update and delete in this data Source I got an exception told me that :
javaScript runtime error:
Sys.WebForms.PageRequestManagerServerErrorException: Could not find a
row that matches the given keys in the original values stored in
ViewState. Ensure that the 'keys' dictionary contains unique key
values that correspond to a row returned from the previous Select
operation.
How Can I solve this exception ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该在Gridview属性中添加
DataKeyNames="ID"
ID是数据库表的关键列。You should add
DataKeyNames="ID"
in Gridview properties ID is the key column of the database table .可能是您在循环或使用 gridview 的 ViewState 时删除了一些行。尝试使用虚拟数据视图来删除所需的行。
May be you are deleting some rows while looping or using the ViewState of the gridview. Try to take a dummy dataview to delete the rows required.
这就像当页面回发到服务器时将网格重新绑定到其他数据一样 - 键的集合在页面呈现时保留在 ViewState 中,用户选择一行,但回到服务器上重新绑定网格并用户选择的密钥在密钥集合中不可用。
It's just like you were rebinding the Grid to some other data when the page is posted back to the server - the collection of keys is persisted in the ViewState upon page rendering, the user selects one row but back on the server you rebind the grid and the key selected by the user is not available in the keys collection.
刚刚升级旧的 VB.net 项目时出现错误,即使它可以在旧项目中运行,新项目也是 VB.Net,“DataKeyName”是 CASE-SENTIVE....
这意味着:
KeyId 与 KeyID 不同
Dammm...
Just got the error when upgrading an old VB.net project, and even it works in the old one, and the new project also is VB.Net the "DataKeyName" is CASE-SENTIVE....
That means:
KeyId is not the same as KeyID
Dammm...