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

[Solved] Heirarchy Delete Error

3 Answers 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 24 Sep 2009, 09:48 PM

Hi,

I'm having a problem when I delete the last item in a detail table, which causes the parent row to be deleted as well.
I get client errors saying "Parent table relations set, but no corresponding data-key name found" and "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"

The master table and the detail table are both bound at the same time during the grids NeedDataSource event.  I have tried setting the HierarchyLoadMode to different values, but it didn't help. 

The delete command item is on the child table.  The delete happens successfully, the DataSource is set to null, the NeedDataSource event occurs, and table is given new data for both the master table and the detail table.

The error only happens when the row is the very LAST row in the grid and all the child items are deleted, causing the parent row to disappear.  If it’s the first row or one of the middle rows, no error occurs.  If it is the only row in the grid you receive the error "Parent table relations set, but no corresponding data-key name found".  If there's more than 1 row, you get the "Index was out of range" error.

Anyone ever encounter anything like this?  Any ideas for workarounds?

Thanks

-Adam

 

3 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 30 Sep 2009, 05:25 AM
Hello Adam,

This is most probably caused by an improper population of the control with data. The best approach in this case, is to use the NeedDataSource event handler for the master table, and the DetailTableDataBind for the detail table(s). This is demonstrated in the following example:

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/detailtabledatabind/defaultcs.aspx

I hope it gets you started properly.

Greetings,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Adam
Top achievements
Rank 1
answered on 30 Sep 2009, 08:51 PM

I am already using NeedDataSource to bind to the grid.  I tried the DetailTableDataBind event, but it didn't help (same error).  In fact, the event doesn't even fire for the deleted row.

I attached a sample program to a support ticket.    If I ever find a fix, I'll post my results here.

0
Adam
Top achievements
Rank 1
answered on 07 Oct 2009, 02:50 PM
protected void RadGrid1_DeleteCommand(object source, GridCommandEventArgs e)    
        {    
            GridDataItem dataItem = (GridDataItem)e.Item;    
            string OrderID = dataItem.GetDataKeyValue("OrderID").ToString();    
            PerformNonQuery(String.Format("Delete FROM [Order Details] WHERE OrderID = '{0}'", OrderID));    
            PerformNonQuery(String.Format("Delete FROM Orders WHERE OrderID = '{0}'", OrderID));    
    
            e.Canceled = true;    
    
            RadGrid1.MasterTableView.Rebind();    
        }    
 

I got this issue fixed with help from support.  To fix it, you need to add e.Canceled = true; in the DeleteCommand event.

-Adam
Tags
Grid
Asked by
Adam
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Adam
Top achievements
Rank 1
Share this question
or