Find Gridview within a Gridview/ItemTemplate within Table within Panel within CollapsablePanel


I am in the process of designing forms and have not bound my grids yet, but can display 1 row of my grids using a simple procedure.
All of my grids are available in code behind except this one that is embedded into one of my grids.
I have tried the findcontrol and it always returns nothing.
The hierarchy of the form is
               GridView       ***** Can't find this one

I am trying to find it in the Parent Grid Load Event

Protected Sub grdServiceDetails_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdServiceDetails.Load
          Dim grd As GridView = DirectCast(grdServiceDetails.FindControl("grdProductsUsed"), GridView)
          If Not grd Is Nothing Then
          End If
     End Sub

Open in new window

Who is Participating?
karthitronConnect With a Mentor Commented:
You want to access the grid view which resides in another grid view's Item Template. Then instead of directly getting the inner grid from parent grid, you have to iterate through each row in parent grid and find the inner grid in each row or each row's specific cell (for demonstating I used cell index as zero, you can specify the valid cell index otherwise simply you can use row object instead of cell object). Following is sample code:
Protected Sub GridView1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.Load
        For Each gvr As GridViewRow In GridView1.Rows
            Dim grd As GridView = DirectCast(gvr.FindControl("grdProductsUsed"), GridView)
            'Dim grd As GridView = DirectCast(gvr.Cells[0].FindControl(""), GridView)
            If Not grd Is Nothing Then
            End If
    End Sub

Open in new window

SheritlwAuthor Commented:
Thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.