Q:

Null Exception declaring gridview in codebehind

Part of this issue is stemming from embedding a GridView in a FormView and running SQL on the GridView controls.
GirdView Markup:
<asp:GridView ID="gvBFProd" runat="server" ShowFooter="True" AutoGenerateColumns="False" DataKeyNames="BFProdID" DataSourceID="BFProdSQL" OnRowCommand="gvBFProd_RowCommand">
            <Columns>
                <asp:TemplateField ShowHeader="False">
                    <EditItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Save"></asp:LinkButton>
                        &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:LinkButton ID="ButtonAdd" runat="server" CommandName="FooterInsert" Text="Insert"  />
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"></asp:LinkButton>
                        &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
...

CodeBehind
private GridView gvBFProd;
    protected void gvBFProd_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        gvBFProd = FormView1.Row.FindControl("gvBFProd") as GridView;

        if (e.CommandName == "FooterInsert" && Page.IsValid)
        {
            // Reference GridView Controls
            TextBox txtBFID = (TextBox)FormView1.Row.FindControl("txtBFID");
            DropDownList ddlSeries =
                (DropDownList)gvBFProd.FooterRow.FindControl("ddlFooterSeries");
            TextBox txtACMWelders =
                (TextBox)gvBFProd.FooterRow.FindControl("txtFooterACMWelders");
....                

// Update InsertParameters
            BFProdSQL.InsertParameters.Clear();

            BFProdSQL.InsertParameters.Add("BFID", txtBFID.Text);
            BFProdSQL.InsertParameters.Add("SeriesID", ddlSeries.SelectedValue);
            BFProdSQL.InsertParameters.Add("NumACMWelders", txtACMWelders.Text);
...         

// Insert new record
            BFProdSQL.Insert();
        }
    }

The initial private GridView gvBFProd; was necessary to give context to the GridView control references due to being embedded in the FormView. However, either something isn't passing correctly or there's something more I need to do with the private GridView gvBFProd; line. I'm thinking the latter as once the project is built, I get the green squiggly under gvBFProd stating the field is never assigned to, and will always have its default value null. And of course when I click on the Insert LinkButton, I get an unhandled Null Exception error that breaks at the (DropdownList)gvBFProd.FooterRow.... line.
Do I need to build get/set funtions for gvBFProd or is there a different way of passing the GridView?

A:

Found what was causing the original Null Exception errors. I was missing the definition of gvBFProd in the codebehind.
Specifically:
private GridView gvBFProd;
    protected void gvBFProd_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        gvBFProd = FormView1.Row.FindControl("gvBFProd") as GridView;
....

Now I'm getting a different Null Reference Exception on my dropdown lists, but that's a different issue.

