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

How to obtain master record ID in details insert mode

1 Answer 15 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 05 Jul 2013, 08:07 PM
I need to do an insert of a details record but I need to obtain the master record ID.  During the InsertCommand event, I have the GridDataInsertItem and I then create a GridTableView of the master table using this:

Dim parenttable As GridTableView = inserteditem.OwnerTableView.ParentItem.OwnerTableView


I used this article thinking it would work as it mentions the GridTableView but I've come up blank.  How can I obtain the value?

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 06 Jul 2013, 03:51 AM
Hello,

Please try with the below code snippet.

ASPX
<MasterTableView CommandItemDisplay="Top" DataKeyNames="ID" Name="parent">
    <DetailTables>
        <telerik:GridTableView Name="Child" DataKeyNames="Name">
        </telerik:GridTableView>
    </DetailTables>
    <Columns>
      ..........
      ...........
    </Columns>
</MasterTableView>

ASPX.VB

Protected Sub RadGrid1_InsertCommand(sender As Object, e As GridCommandEventArgs)
    If e.Item.OwnerTableView.Name = "Child" Then
        Dim item As GridDataInsertItem = TryCast(e.Item, GridDataInsertItem)
        Dim pitem As GridDataItem = TryCast(item.OwnerTableView.ParentItem, GridDataItem)
            ' Parent Item DataKey Here
        Dim strID As String = pitem.GetDataKeyValue("ID").ToString()
    End If
End Sub


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Jon
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or