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

Getting the DataKeyValue of an Inserted Item in the Child of a Hierarchy

3 Answers 167 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David Kelleher
Top achievements
Rank 1
David Kelleher asked on 20 Jun 2011, 03:11 AM
Could someone please help me with the correct code to reference the DataKeyValue in the Child item of a Hierarchy using ItemInserted.  I have tried the following code but don't get the datakey returned at the Child ("Sheds") level.
Protected Sub RadGrid1_ItemInserted(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridInsertedEventArgs) Handles RadGrid1.ItemInserted
    If e.Exception Is Nothing Then
        Dim editedItem As GridEditableItem = e.Item
        If "Placements".Equals(editedItem.OwnerTableView.Name) Then
            Dim gridRows As GridItemCollection = RadGrid1.Items
            Dim id As Int32 = 0
            For Each data As GridDataItem In gridRows
                id = Math.Max(id, data.GetDataKeyValue("PlanMasterId"))
            Next
            UpdateFarmPerformance(id)
        ElseIf "Sheds".Equals(editedItem.OwnerTableView.Name) Then
            'Update the Placment details from the shed details
            Dim parentItem As GridDataItem = editedItem.OwnerTableView.ParentItem
            Dim id As Int32 = parentItem.OwnerTableView.DataKeyValues(parentItem.ItemIndex)("PlanMasterId")
            updatePlacements(id)
            Dim gridRows As GridItemCollection = e.Item.OwnerTableView.Items
            Dim id2 As Int32 = 0
            For Each data As GridDataItem In gridRows
                id2 = Math.Max(id2, data.GetDataKeyValue("PlanMasterShedId"))
            Next
            UpdateShedPerformance(id2)
            UpdateFarmPerformance(id)
        End If
    End If
End Sub
Thanks

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 Jun 2011, 09:04 AM
Hello David,

I am not quite sure about your requirement and and I suppose you want to access the DataKeyValues of the parent item when inserting ChilldItem.

VB.NET:
Protected Sub RadGrid1_ItemInserted(sender As Object, e As Telerik.Web.UI.GridInsertedEventArgs)
  
    Dim item As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem)
    Dim customerId1 As String = item.OwnerTableView.ParentItem.GetDataKeyValue("Id").ToString()//accessing parent table  DataKey Value.
    Response.Write(customerId1)
  
End Sub

Thanks,
Shinu.
0
David Kelleher
Top achievements
Rank 1
answered on 21 Jun 2011, 01:01 AM
Shinu,
It's not getting the datakey of the parent.  I'm having trouble getting the datakey of the inserted item at the child level.

Thanks,
David
0
Vasil
Telerik team
answered on 23 Jun 2011, 09:50 AM
Hi David,

Could you confirm that "PlanMasterShedId" is set in the DataKeyNames of the GridTableView used for detail table?

All the best,
Vasil
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
David Kelleher
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
David Kelleher
Top achievements
Rank 1
Vasil
Telerik team
Share this question
or