开发者

exception when I tried to update my gridview in asp.net

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 return开发者_StackOverflowed from the previous Select operation.

How Can I solve this exception ?


You should add DataKeyNames="ID" in Gridview properties ID is the key column of the database table .


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.


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.


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜