locked
Need help finding ID of parent in nested gridivew RRS feed

  • Question

  • User-740453238 posted

    I have a nested gridivew.  When I try to add record to the child gridivew I can't figure out the ID of the parent.  I am pressing a + sign to open up the child.  If I click on select then I have no problem.  However the + doesn't actually select the parent.  So how can I do this.  Either figuring out how to find the ID or causing the record to be selected when I click on the +.  You can see my tries below.

    If e.CommandName = "AddComment" Then

    'Dim gvUniqueID As String = [String].Empty

    Try

    Dim gvTemp As GridView = DirectCast(sender, GridView)

    Dim strTicketsID1 As Integer = GridView1.SelectedValue 'GridView1.DataKeys(e.row).Values("TicketID")

    'Dim key As String = Me.GridView1.DataKeys(TryCast(TryCast(row.NamingContainer, GridView).NamingContainer, GridViewRow).RowIndex).Value.ToString()

    Dim ParentKey As Integer = Convert.ToInt32(DirectCast(gvTemp.Parent.FindControl("TicketID"), TextBox).Text)

    'Dim ParentKey1 As Integer = Convert.ToInt32(DirectCast(GridView1.Rows(gvTemp.Parent).FindControl("TicketID"), Label).Text)

    ' Dim Gv2Row As GridViewRow = DirectCast(DirectCast(sender, GridView).NamingContainer, GridViewRow)

    'Dim Childgrid As GridView = DirectCast(gvTemp.Parent.Parent, GridView)

    'Dim Gv1Row As GridViewRow = DirectCast(Childgrid.NamingContainer, GridViewRow)

    '' Dim b As Integer = Childgrid.RowIndex

    Monday, September 5, 2016 10:15 PM

Answers

  • User-740453238 posted

    I finally found the answer.  Just used this code:

    Dim strTicketsID1 As Integer = Me.GridView1.DataKeys(TryCast(gvTemp.NamingContainer, GridViewRow).RowIndex).Value

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 6, 2016 12:16 AM

All replies

  • User-740453238 posted

    I finally found the answer.  Just used this code:

    Dim strTicketsID1 As Integer = Me.GridView1.DataKeys(TryCast(gvTemp.NamingContainer, GridViewRow).RowIndex).Value

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 6, 2016 12:16 AM
  • User61956409 posted

    Hi mhinkle2,

    I’m glad to hear that you resolve the issue by yourself. And thanks for share us your solution. As you did, we could use the NamingContainer property of a naming container's child control to get a reference to its parent container, and then we could find properties or objects from parent container.

    Best Regards,

    Fei Han

    Tuesday, September 6, 2016 7:19 AM