0

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
Stacky Flowy
  • 103
  • 1
  • 10
  • man it's not a duplicate plus i am not that much qualified to understand it from general problem. Please remove the duplication – Stacky Flowy Dec 20 '15 at 12:44
  • and i know that what a null exception is but in my case i cant figre out. Please help instead of sparing yourself by marking it as duplicate – Stacky Flowy Dec 20 '15 at 12:45

0 Answers0