Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
85
Webdatagrid - Rebinding datasource
posted

Hi there!

Please following steps:

1. My example have one DropDownList and one WebDataGrid. I set AutoPostBack = True for the DropDownList.

2. In this scenario, when I change item of DropDownList then the WebDataGrid will be reloading with new DataSource.

3. First of all, I change values of any cells on the grid, then I change item of DropDownList, an error has occurred like this:

"Requested record cannot be found by key.
Common Causes:
- The data key field(s) is being edited causing the record not to be found when trying to update.
- Not rebinding the grid when there are updates to be committed (assuming DataViewState is disabled in this case) – for instance if the grid is bound on !IsPostback.
- While a user is editing a particular row in the grid, another user deletes the record from the database. On posting back, the grid is rebound to the updated datasource which no longer contains the record, resulting in the exception.
- Changing completely or filtering the grid’s datasource before all CRUD operations are carried out – this is quite common when using other controls on the page to do this . This is partly due to the fact that control events such as SelectedIndexChanged for a dropdownlist or Click for a button fire before the updating events. Changing the grid’s source should in such cases be delayed for later (PreRender)."

I have tried ClearDatasource() before ReBind() the DataSource of WebDataGrid, but this could not resolved the error.

I'm using NetAdvantage 14.1.20141.2150 lastest released.

Please help me out of this problem.

Best regard, Slim.

WebTest.zip
Parents
No Data
Reply
  • 10685
    Verified Answer
    Offline posted

    Hello and welcome to the community, 

    When CRUD operations are handled, it is required the WebDataGrid to have access to the DataSource the modified records were a part of.  If the grid’s DataSource is changed before the CRUD operations events are fired, at the time they do the grid has a different DataSource hence the CRUD operations cannot be completed and an exception fires. You could a handler for the updating/put a breakpoint and see when it is hit. SelectedIndexChanged event of the dropdownlist fires first, before CRUD operations. At this point "Requested record cannot be found" exception will be raised.

    You could use a session variable in order to persist the current DataSource used. On each Page_Load, the grid can be rebound to the same DataSource to which it was bound last (on a previous postback), to ensure that grid updates can be handled accordingly. On the dropdown list’s SelectedIndexChanged the grid is not bound to the new DataSource. Instead, the grid is rebound to the new DataSource (and the current DataSource session variable is updated) at the PreRender stage, when all CRUD operations have already been handled. 

    Please let me know if you require additional assistance!

Children