I have a ParentGridview which contains ChildGridview inside a Panel and inside an **ItemTemplateField**
. Now in coding I want to get the ParentGridview and via that I want to access that Panel but can't achieve.
aspx: (*
Don't go with the syntax, i just wrote it here in exact style of original code*
)
<asp:gridview id="ParentGv" runat="server">
<columns>
<asp:templatefield>
<itemtemplate>
<asp:panel id="childpanel" runat="server">
<asp:gridview id="ChildGv" runat="server" onrowcommand="ChildGv_Rowcommand">
<columns>
<asp:templatefield>
<itemtemplate>
<asp:imagebutton id="btndelete" runat="server" CommandName="cmdDelete" CommandArgument='<%# Container.DataItemIndex %>'
</itemtemplate>
</asp:templatefield>
<columns/>
</panel>
</itemtemplate>
</asp:templatefield>
</columns>
MyCode:
protected void ChildGv_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
GridView grdviewCaseHearingsDetails = (GridView)sender;
int index = Convert.ToInt32(e.CommandArgument);
if (e.CommandName == "cmdDelete")
{
GridView ChildGv = (GridView)((ImageButton)(e.CommandSource)).Parent.Parent.Parent.Parent;
GridView ParentGv = (GridView)(ParentGv.Parent.Parent.Parent.Parent.Parent);
ParentGv.FindControl("childpanel").Visible = true;
}
but this keeps me giving the error at last line:
Object reference not set to an instance of an object