Mudassir Hasan
Mudassir Hasan

Reputation: 28771

Nested child GridView onrowedit error

I am using a Gridview inside another GridView. I want to implement edit / update in child Gridview.

<asp:TemplateField>
  <ItemTemplate>
    <asp:GridView ID="gvChildGrid" runat="server" AutoGenerateColumns="false"
                      onrowediting="gvChildGrid_RowEditing" >
  </ItemTemplate>
</asp:Template>

onrowedit for child gridview is like below

protected void gvChildGrid_RowEditing(object sender, GridViewEditEventArgs e)
{
  gvChildGrid.EditIndex = e.NewEditIndex;
  BindData();
}

This is showing error

gvChildGrid doesnot exist in current context .

Please help how to implement edit /Update child gridview

Upvotes: 0

Views: 397

Answers (1)

Grundy
Grundy

Reputation: 13381

try change your code like this

protected void gvChildGrid_RowEditing(object sender, GridViewEditEventArgs e)
{

    ((GridView)sender).EditIndex = e.NewEditIndex;
    BindData();

}

UPDATE
in runtime you cann't get nested gridview by name, because it inside template field, so you can get it from sender object

Upvotes: 1

Related Questions