Nested grid edit doesn't work
<p>I'm stuck on this problem where I have grid within grid where the nested grid is editable. I can't get the edit working. What's complicates things is that the nested grid is inside a modal popup extender. </p>

<p>It works to the point where I click on the edit button. Then the EmptyDataText property kicks in with the message. If I click on it second time the grid opens in edit mode but the update/cancel buttons don't work. The cancel button when click displays the EmptyDataText property.</p>

<p>Another issue is that this nested grid doesn't use a object data source so I'm going to have to all the updating and deleting in the code file. Not sure now to do that either.</p>

<p>I would like some advice as to how to make this corrected. Here is the code:</p>

<pre><code>&lt;asp:GridView ID="gvForum" runat="server" DataSourceID="odsForumApproval" DataKeyNames="id" Width="200px"
RepeatColumns="1" DataKeyField="id" CssClass="gridview"
AutoGenerateColumns="False" GridLines="None" OnSelectedIndexChanged="_OnCommand"&gt;
&lt;AlternatingRowStyle CssClass="altbgcolor"  /&gt;
&lt;Columns&gt;
    &lt;asp:TemplateField &gt;
        &lt;ItemTemplate&gt;
            &lt;asp:Label runat="server" ID="lblTitle" Text='&lt;%# Bind("Title") %&gt;' /&gt;

            &lt;asp:Panel id="div" runat="server" align="center" class="confirm" style="display:none"  &gt;
                &lt;asp:GridView runat="server" ID="gvForumDetail" AutoGenerateColumns="False" DataKeyNames="id"
                    AllowPaging='true' CssClass="gridview" 
                    AllowSorting="true" PageSize="5" CellPadding="5" OnRowEditing="gvForumDetail_OnRowEditing"
                    OnRowCancelingEdit="gvForumDetail_CancelRecord"  &gt;
                    &lt;AlternatingRowStyle CssClass="altbgcolor" /&gt;
                    &lt;RowStyle VerticalAlign="Top" HorizontalAlign="Left" /&gt;
                    &lt;HeaderStyle  CssClass="greenbar" ForeColor="White" /&gt; &lt;Columns&gt;
                        &lt;asp:BoundField DataField="id" ReadOnly="true" Visible="false" /&gt;
                        &lt;asp:TemplateField HeaderText="Title"&gt;
                            &lt;ItemTemplate&gt;
                                &lt;asp:Label runat="server" ID="lblTraining" Text='&lt;%# Bind("title") %&gt;' /&gt;
                            &lt;/ItemTemplate&gt;
                            &lt;EditItemTemplate&gt;
                                &lt;asp:TextBox runat="server" ID="txtTraining" Text='&lt;%# Bind("title") %&gt;' /&gt;
                            &lt;/EditItemTemplate&gt;
                        &lt;/asp:TemplateField&gt;
                        &lt;asp:TemplateField HeaderText="Post Message"&gt;
                            &lt;ItemTemplate&gt;
                                &lt;asp:Label runat="server" ID="lblCompletionDate" Width="250"  Text='&lt;%# Bind("description") %&gt;' /&gt;
                            &lt;/ItemTemplate&gt;
                            &lt;EditItemTemplate&gt;
                                &lt;asp:TextBox runat="server" ID="txtDescription" Text='&lt;%# Bind("description") %&gt;' TextMode="MultiLine" Rows="5" Width="250" /&gt;
                            &lt;/EditItemTemplate&gt;
                        &lt;/asp:TemplateField&gt;
                        &lt;asp:TemplateField HeaderText="Posted By"&gt;
                            &lt;ItemTemplate&gt;
                                &lt;asp:Label runat="server" ID="lblRecurence" Text='&lt;%# Bind("MemberName") %&gt;' /&gt;
                            &lt;/ItemTemplate&gt;
                        &lt;/asp:TemplateField&gt;
                        &lt;asp:TemplateField HeaderText="Posted Date"&gt;
                            &lt;ItemTemplate&gt;
                                &lt;asp:Label runat="server" ID="lblNotes" Text='&lt;%# Eval("itemdate", "{0:d}") %&gt;'  /&gt;
                            &lt;/ItemTemplate&gt;
                            &lt;EditItemTemplate&gt;
                                &lt;asp:CheckBox runat="server" ID="cbxApproved" Text='&lt;%# Bind("approved") %&gt;' /&gt;
                            &lt;/EditItemTemplate&gt;
                        &lt;/asp:TemplateField&gt;
                        &lt;asp:CommandField ShowCancelButton="true" ShowEditButton="true" ShowDeleteButton="true" /&gt;
                    &lt;/Columns&gt;
                &lt;/asp:GridView&gt;
                &lt;br /&gt;
                &lt;Club:RolloverLink ID="btnClose" runat="server" Text="Close" /&gt;
            &lt;/asp:Panel&gt;

            &lt;ajaxToolKit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
                TargetControlID="lblTitle"
                PopupControlID="div"
                CancelControlID="btnClose"
                BackgroundCssClass="modalBackground" /&gt;

        &lt;/ItemTemplate&gt;
    &lt;/asp:TemplateField&gt;
    &lt;asp:CommandField ShowSelectButton="True"  /&gt;
&lt;/Columns&gt;
</code></pre>

<p></p>

<p>Code behind:</p>

<pre><code>public void _OnCommand(object sender, EventArgs e)
{
    ObjectDataSource ods = new ObjectDataSource();
    ods.ID = "ods_ForumDetail";
    ods.EnableViewState = true;
    ods.TypeName = "ForumApproval";
    ods.SelectMethod = "GetForumById";

    string id = "";
    int rowIndex = gvForum.SelectedIndex;
    id = gvForum.DataKeys[rowIndex].Value.ToString();
    ods.SelectParameters.Add("id", System.TypeCode.Int32, id);

    var ModalPopupExtender1 = (ModalPopupExtender)(gvForum.SelectedRow.FindControl("ModalPopupExtender1"));
    ModalPopupExtender1.Show();

    var gvForumDetail = (GridView)(gvForum.SelectedRow.FindControl("gvForumDetail"));
    gvForumDetail.DataSource = ods;
    gvForumDetail.DataBind();
}

protected void gvForumDetail_OnRowEditing(Object sender, GridViewEditEventArgs e)
{
    var ModalPopupExtender1 = (ModalPopupExtender)(gvForum.SelectedRow.FindControl("ModalPopupExtender1"));
    ModalPopupExtender1.Show();

    var gvForumDetail = (GridView)(gvForum.SelectedRow.FindControl("gvForumDetail"));

    gvForumDetail.EditIndex = e.NewEditIndex;
    gvForumDetail.DataBind();
}

protected void gvForumDetail_CancelRecord(object sender, GridViewCancelEditEventArgs e)
{
    var ModalPopupExtender1 = (ModalPopupExtender)(gvForum.SelectedRow.FindControl("ModalPopupExtender1"));
    ModalPopupExtender1.Show();

    var gvForumDetail = (GridView)(gvForum.SelectedRow.FindControl("gvForumDetail"));
    gvForumDetail.EditIndex = -1;
    gvForumDetail.DataBind();
}
</code></pre>
