Hello,
I have a RadGrid with nested tables, for now called parent and child. It is a business rule that no parents can be childless, and that only the children can be removed. This results in a situation where the parent will have to be deleted when the last child is deleted.
At the moment, in the OnDeleted method, I am using
to remove the parent item, after checking if the parent is now empty.
This results in a ArgumentOutOfRangeException at:
I assume because it's looking for a non-existent parent element when trying to create the now empty detailtable.
Can anyone help me resolve this situation. Basically I want the parent item removed when a child item is removed. I tried using the NeedDataSource event to check for empty parents and remove them directly on the database, but I'm not having much success with assigning already existing DataSources to the master and detail tables.
Thanks
I have a RadGrid with nested tables, for now called parent and child. It is a business rule that no parents can be childless, and that only the children can be removed. This results in a situation where the parent will have to be deleted when the last child is deleted.
At the moment, in the OnDeleted method, I am using
item.FireCommandEvent(RadGrid.DeleteCommandName, ""); |
This results in a ArgumentOutOfRangeException at:
at System.Collections.ArrayList.get_Item(Int32 index) |
at Telerik.Web.UI.GridDataKeyArray.get_Item(Int32 index) |
at Telerik.Web.UI.GridTableView.FilterDetailDataSource() |
at Telerik.Web.UI.GridTableView.DataBind() |
at Telerik.Web.UI.GridTableView.Rebind() |
I assume because it's looking for a non-existent parent element when trying to create the now empty detailtable.
Can anyone help me resolve this situation. Basically I want the parent item removed when a child item is removed. I tried using the NeedDataSource event to check for empty parents and remove them directly on the database, but I'm not having much success with assigning already existing DataSources to the master and detail tables.
Thanks
11 Answers, 1 is accepted
0
Hi Flappie,
Indeed, based on the provided information I assume that the parent item is not referenced properly. Can you paste here the entire OnItemDeleted event handler for further investigation?
Best wishes,
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.
Indeed, based on the provided information I assume that the parent item is not referenced properly. Can you paste here the entire OnItemDeleted event handler for further investigation?
Best wishes,
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

Flappie
Top achievements
Rank 1
answered on 23 Apr 2010, 01:14 PM
Hello,
Thanks for replying.
This is the code I'm using at the moment:
I have also tried this:
I'm fairly certain the item is being referenced properly, I think it's the programmatic deletion when values in viewstate still expect it to exist that causes a problem.
The whole grid is Ajaxified by the way, not sure if that makes a difference.
Thanks for replying.
This is the code I'm using at the moment:
protected void QuoteItemsRadGrid_ItemDeleted(object source, GridDeletedEventArgs e) |
{ |
if (e.Item.OwnerTableView.Items.Count -1 == 0) |
{ |
GridDataItem item = e.Item.OwnerTableView.ParentItem; |
if (item.GetDataKeyValue("QuoteItemGroupID") != null) |
{ |
item.FireCommandEvent(RadGrid.DeleteCommandName, ""); |
} |
} |
} |
I have also tried this:
protected void QuoteItemsRadGrid_ItemDeleted(object source, GridDeletedEventArgs e) |
{ |
int? group = QuoteData.FindEmptyQuoteGroup(Quote); |
if (group.HasValue) |
{ |
foreach (GridDataItem item in QuoteItemsRadGrid.Items) |
{ |
if (item.GetDataKeyValue("QuoteItemGroupID") != null && item.GetDataKeyValue("QuoteItemGroupID").ToString() == group.Value.ToString()) |
{ |
item.FireCommandEvent(RadGrid.DeleteCommandName, ""); |
} |
} |
} |
} |
I'm fairly certain the item is being referenced properly, I think it's the programmatic deletion when values in viewstate still expect it to exist that causes a problem.
The whole grid is Ajaxified by the way, not sure if that makes a difference.
0
Hello Flappie,
Indeed, the code in the ItemDeleted event handler is proper and it works on my side as expected. Can you try the attached sample and let me know how it works on your end and let me know what differs in your case?
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.
Indeed, the code in the ItemDeleted event handler is proper and it works on my side as expected. Can you try the attached sample and let me know how it works on your end and let me know what differs in your case?
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

Flappie
Top achievements
Rank 1
answered on 27 Apr 2010, 03:31 AM
Hello,
I tried the example. I added a new employee, and then added a new order for that employee. The delete button deletes the order and the employee (after a refresh), but I get a popup with:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
That's the same problem as I'm having in my scenario.
I tried the example. I added a new employee, and then added a new order for that employee. The delete button deletes the order and the employee (after a refresh), but I get a popup with:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
That's the same problem as I'm having in my scenario.
0
Hello Flappie,
I was able to replicate the error. I also observed that it is thrown only in case you are trying to delete the last item on the page. However we will need a bit more time to find a proper resolution for it.
Currently to overcome that issue, I suggest that you fire the delete command for the parent item on RadGrid PreRender instead of in the ItemDeleted event handler. You can find the modified project attached and see 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.
I was able to replicate the error. I also observed that it is thrown only in case you are trying to delete the last item on the page. However we will need a bit more time to find a proper resolution for it.
Currently to overcome that issue, I suggest that you fire the delete command for the parent item on RadGrid PreRender instead of in the ItemDeleted event handler. You can find the modified project attached and see 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

Rich Evans
Top achievements
Rank 1
answered on 29 Apr 2010, 02:37 AM
Hello,
Yep, that works great. Thank you for the help.
Yep, that works great. Thank you for the help.
0

Tri Nguyen
Top achievements
Rank 1
answered on 31 Mar 2011, 05:48 PM
I currently have the same problem: when removing any child record from the last parent record, I got the error messge:
Index was out of range. Must be non-negative and less than the size of the collection.
I wonder if you have fixed this problem or any other work around. I have tried to use the sample code in "website2.zip" file, but couldn't make it work for me. I am using version 2010.3.1215.40. Let me know. Thanks.
Tri
Index was out of range. Must be non-negative and less than the size of the collection.
I wonder if you have fixed this problem or any other work around. I have tried to use the sample code in "website2.zip" file, but couldn't make it work for me. I am using version 2010.3.1215.40. Let me know. Thanks.
Tri
0
Hi Tri,
If I properly understand you are not able to replicate the issue in the sample I provided in my previous post. ANd you are using the same code in your application. Can you specify at which line is the error thrown? Is it in the ItemDeleted or grid PreRender event handler?
You can also try setting the HierarchyLoadMode of the MasterTableView to ServerBind and see if it makes any difference.
Greetings,
Iana
the Telerik team
If I properly understand you are not able to replicate the issue in the sample I provided in my previous post. ANd you are using the same code in your application. Can you specify at which line is the error thrown? Is it in the ItemDeleted or grid PreRender event handler?
You can also try setting the HierarchyLoadMode of the MasterTableView to ServerBind and see if it makes any difference.
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

Tri Nguyen
Top achievements
Rank 1
answered on 04 Apr 2011, 03:56 PM
Protected Sub rgdCallList_DeleteCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgdCallList.DeleteCommand
Dim LoggedInUser As dbUser = CType(Session("AccessUser"), dbUser)
'Dim msg As String = CallListNoteMgr.DeleteNote(LoggedInUser.Profile_ID, e.Item.OwnerTableView.DetailTables(0).DataKeyValues(e.Item.ItemIndex)("call_list_note_id"))
Dim msg As String = CallListNoteMgr.DeleteNote(LoggedInUser.Profile_ID, e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("call_list_note_id"))
If IsNumeric(msg) Then
e.Item.OwnerTableView.Rebind()
'e.Item.OwnerTableView.ClearChildEditItems()
'e.Item.OwnerTableView.ClearEditItems()
rgdCallList.Rebind()
'rgdCallList.MasterTableView.Rebind()
'e.Item.OwnerTableView.ParentItem.OwnerTableView.Rebind()
End If
End Sub
Hello, Iana,
It's the Rebind line that generates that error. Even when I put the code in the ItemCommand, the same error occured. And putting the code segment in the PreRender didn't make any difference. If you have any suggestion, let me know. Thanks.
Here is the code that I have.
0
Hello Tri,
After the DeleteCommand the grid is implicitly rebound as described here. I assume that is why calling rebind explicitly ends up with an error. You should either remove the explicit rebind, or cancel the default command (e.Canceled = true;).
Regards,
Iana
the Telerik team
After the DeleteCommand the grid is implicitly rebound as described here. I assume that is why calling rebind explicitly ends up with an error. You should either remove the explicit rebind, or cancel the default command (e.Canceled = true;).
Regards,
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

Tri Nguyen
Top achievements
Rank 1
answered on 06 Apr 2011, 03:59 PM
Iana,
Cancelling the default command (e.Canceled = true) works, in my case. Simply removing the explicit rebind only refreshed the child table, not the parent one. Thanks so much for your help.
Tri
Cancelling the default command (e.Canceled = true) works, in my case. Simply removing the explicit rebind only refreshed the child table, not the parent one. Thanks so much for your help.
Tri