Answered by:
Change sort order causes error on delete

Question
-
User1356301571 posted
Hi!
I have created a custom List.aspx page for a certain table, in which (in the Page_Load event) I call the Sort method of the GridView, in order to set the initial sort order of data. This works but, when I try to delete a record using the Delete link, I obtain the following error message:
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.
All the other operation works correctly. Cound anyone help me solving the problem?
Thanks in advance.
Saturday, April 25, 2009 12:28 PM
Answers
-
User-1005219520 posted
We're investigating. You might need to call sort in Page_Init, not Page_Load.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, April 28, 2009 2:23 PM -
User1356301571 posted
Instead I tried this way and it works correctly:
protected void Page_Init(object sender, EventArgs e) { DynamicDataManager1.RegisterControl(GridView1, true /*setSelectionFromUrl*/); table = GridDataSource.GetTable(); if (!Page.IsPostBack) { GridView1.Sort("Name", SortDirection.Ascending); } }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, April 28, 2009 2:41 PM
All replies
-
User-330204900 posted
It sounds like you have not set the keys dictionary on the GridView. I'm assuming that you have setup the data source manually.
Saturday, April 25, 2009 3:08 PM -
User1356301571 posted
No, I haven't setup the data source manually, I rely on the Dynamic Data Framework for data binding. When I enter the GridView_RowDeleteing event, the Keys dictionary is empty. But the strange thing is that, if I don't sort the GridView in the Page_Load event, this dictionary is correctly populated.
It sounds strange...
Tuesday, April 28, 2009 3:21 AM -
User-330204900 posted
Could be a bug I'll try it in Northwind.
Tuesday, April 28, 2009 4:03 AM -
User1356301571 posted
Thank you very much for your attention!
Tuesday, April 28, 2009 4:21 AM -
User-330204900 posted
Yep I get this error:
Server Error in '/' Application.
Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OptimisticConcurrencyException: Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[OptimisticConcurrencyException: Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.] System.Data.Mapping.Update.Internal.UpdateTranslator.ValidateRowsAffected(Int64 rowsAffected, UpdateCommand source) +4050392 System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter) +410 System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache) +165 System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options) +639 System.Web.UI.WebControls.EntityDataSourceView.ExecuteDelete(IDictionary keys, IDictionary oldValues) +565 System.Web.UI.DataSourceView.Delete(IDictionary keys, IDictionary oldValues, DataSourceViewOperationCallback callback) +92 System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex) +976 System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +1039 System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +95 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +121 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37 System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +118 System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +169 System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +176 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4915
Version Information: Microsoft .NET Framework Version:4.0.20409; ASP.NET Version:4.0.20409.1
May be bug or just a bad prctice we'll just have to wait and see what one of the team says [:(]
Tuesday, April 28, 2009 4:49 AM -
User1356301571 posted
And so... Can we inform Microsoft about this problem?
Tuesday, April 28, 2009 7:43 AM -
User-330204900 posted
Members of the ASP.Net teamare on this forum and will hopefully comment on the issue.
Tuesday, April 28, 2009 7:47 AM -
User-1005219520 posted
We're investigating. You might need to call sort in Page_Init, not Page_Load.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, April 28, 2009 2:23 PM -
User-330204900 posted
<STRIKE>oops did'nt try that [:$]</STRIKE>
Just tried it in the Page_Init and still the same [:S]
Tuesday, April 28, 2009 2:28 PM -
User1356301571 posted
Instead I tried this way and it works correctly:
protected void Page_Init(object sender, EventArgs e) { DynamicDataManager1.RegisterControl(GridView1, true /*setSelectionFromUrl*/); table = GridDataSource.GetTable(); if (!Page.IsPostBack) { GridView1.Sort("Name", SortDirection.Ascending); } }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, April 28, 2009 2:41 PM