Master Detail Null Reference Exception
<p>Loking for your insight as to why I'm getting this error, actually better yet, how to fix it. I have a nested gridview inside gridview. There may be a better way but at this point I've got the modal popup to work which also took forever, so unless this is completely stupid way to display master-detail then say so now.</p>

<p>I am able to pass the datakey id to the detail grid but that is where I get the null reference exception, I guess the bugger doesen't exist yet, or is not visible. I mean, what-ever-the-reason is, how do I fix this? Thanks in advace.</p>

<p>aspx file:</p>

<pre><code>&lt;asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"&gt;
    &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"
      EmptyDataText="No Forum Detail"  AllowPaging='true'
      AllowSorting="true" PageSize="5"  &gt;
      &lt;AlternatingRowStyle CssClass="altbgcolor" /&gt;
      &lt;RowStyle VerticalAlign="Top" HorizontalAlign="Left" /&gt;
      &lt;Columns&gt;
        &lt;asp:TemplateField&gt;
          &lt;ItemTemplate&gt;
            &lt;asp:Label runat="server" ID="lblTraining" Text='&lt;%# Bind("title") %&gt;' /&gt;
          &lt;/ItemTemplate&gt;
        &lt;/asp:TemplateField&gt;
        &lt;asp:TemplateField&gt;
          &lt;ItemTemplate&gt;
            &lt;asp:Label runat="server" ID="lblCompletionDate" Text='&lt;%# Bind("description") %&gt;' /&gt;
          &lt;/ItemTemplate&gt;
        &lt;/asp:TemplateField&gt;
        &lt;asp:TemplateField&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&gt;
          &lt;ItemTemplate&gt;
            &lt;asp:Label runat="server" ID="lblNotes" Text='&lt;%# Bind("itemdate") %&gt;' Width="200" /&gt;
          &lt;/ItemTemplate&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;asp:Button ID="btnClose" runat="server" Text="Close" Width="50px" /&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" ShowDeleteButton="true" /&gt;
      &lt;/Columns&gt; 
      &lt;/asp:GridView&gt;
</code></pre>

<p>code file:</p>

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

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

    GridView gvForumDetail = (GridView)Master.FindControl("ContentPlaceHolder1").FindControl("gvForum").FindControl("gvForumDetail");
    gvForumDetail.DataSource = ods;
    gvForumDetail.DataBind();
}
</code></pre>
