This is a migrated thread and some comments may be shown as answers.

Cannot rebind parent tableview after update

4 Answers 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Wyatt
Top achievements
Rank 1
Wyatt asked on 15 Apr 2010, 04:19 PM
I have a grid with a master table and a detail/child table.  Both tables have a balance field.  The master table's balance field is the sum of it child balance fields.  When a child record is updated, I want the parent balance to reflect the change.  When I call Rebind() at the end of the UpdateCommand handler for a detail table, Get the following error.

"There was a problem extracting DataKeyValues from the DataSource. Please ensure that DataKeyNames are specified correctly and all fields specified exist in the DataSource."

I read a few treads related to this error but nothing helped for my particular circumstance.

4 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 20 Apr 2010, 11:39 AM
Hi Wyatt,

Could you please canceling the command and then rebinding the grid and see if it makes any difference:

protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
{
   //code for database update
   e.Canceled = true;
   (sender as RadGrid).Rebind();
}


Greetings,
Iana
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Wyatt
Top achievements
Rank 1
answered on 20 Apr 2010, 04:13 PM
The data is refreshed correctly and there is no error.  The only problem is that the edit form stays open.
0
Accepted
Iana Tsolova
Telerik team
answered on 21 Apr 2010, 01:08 PM
Hello Wyatt,

Please excuse me for misleading you.

Try adding the below line for closing the grid edit form after update:

protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e) 
   //code for database update 
   e.Canceled = true
   e.Item.Edit = false;
   (sender as RadGrid).Rebind(); 
}

Let me know if it works for you.

All the best,
Iana
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Wyatt
Top achievements
Rank 1
answered on 21 Apr 2010, 02:52 PM
That works.  Thank you!

Rebind collapses expansions, so I modified your example to persist expansions.

Protected Sub rgGrid_UpdateCommand(ByVal sender As ObjectByVal e As GridCommandEventArgs) Handles rgGrid.UpdateCommand  
    'Perform Update  
    e.Canceled = True 
    e.Item.Edit = False 
    HLWebUtil.ExpandedRebind(sender)  
End Sub 
Public Shared Sub ExpandedRebind(ByVal Grid As RadGrid)  
    Dim KeysExpanded As String() = (From i As GridDataItem In Grid.MasterTableView.Items Where i.Expanded Select i.KeyValues).ToArray  
    Grid.Rebind()  
    For Each Item As GridDataItem In (From i As GridDataItem In Grid.MasterTableView.Items Where KeysExpanded.Contains(i.KeyValues) Select i).ToArray  
        Item.Expanded = True 
    Next 
End Sub 
Tags
Grid
Asked by
Wyatt
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Wyatt
Top achievements
Rank 1
Share this question
or