zagnieżdżony widok siatki pobiera wiersz macierzysty

Korzystam z zagnieżdżonych GridViews, gdzie każdy wiersz wgridview ma dziecko gridView. ja używamRowDataBound Wydarzenie zRodzinny GridView, do BindingDziecko GridView. Moim problemem jest to, jak uzyskać gridViews Child GridView Key on ChildRowDataBound Zdarzenie.

Poniżej znajduje się przykładowy kod:

<asp:GridView ID="gvParent" DataKeyNames="ID" runat="server" PageSize="1" AllowPaging="true" PagerSettings-Mode="NextPrevious" AutoGenerateColumns="False" SkinID="GVCenter" onrowdatabound="gvParent_RowDataBound">
   <Columns>
        <asp:BoundField DataField="Name" />
        <asp:TemplateField>
           <ItemTemplate>
               <asp:GridView ID="gvChild"  DataKeyNames="ID" runat="server" AutoGenerateColumns="false" ShowHeader="false" OnRowDataBound="gvChild_RowDataBound">
                  <Columns>
                     <asp:BoundField DataField="Name" />                     
                  </Columns>
                </asp:GridView>
           </ItemTemplate>
        </asp:TemplateField>
   </Columns>
</asp:GridView>

Oto kod za:

    protected void gvParent_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            GridView gvChild= (GridView)e.Row.FindControl("gvChild");
            gvChild.DataSource = getChildObj();
            gvChild.DataBind();
        }
    }

   protected void gvChild_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // Here I need to get the parent gridview Row Key
        }
    }

Mam nadzieję, że powyższy kod wyjaśnia cały scenariusz.

Z góry dzięki Sandy

questionAnswers(5)

yourAnswerToTheQuestion