0

我有一个ParentGridview Panel**ItemTemplateField**. 现在在编码中,我想获取ParentGridview并通过它访问该面板但无法实现。

aspx:(*不要使用语法,我只是按照原始代码的样式写在这里*

<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>

我的代码:

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;
        }

但这让我在最后一行给出错误:

你调用的对象是空的

4

0 回答 0