aleph_data 0 Newbie Poster

Successfully put two Drop Down Lists into my GridView, now trying to figure out how to retrieve the DataValueField in my code behind

Gridview looks like this

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  DataKeyNames="GameID" onrowcommand="GridView1_RowCommand">
            <Columns>
                <asp:BoundField DataField="GameNumber" HeaderText="GM #" />
                <asp:BoundField DataField="Home" HeaderText="Home" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:DropDownList ID="lstHomeTeams" runat="server" DataSource='<%# teams.GetAllTeams() %>' 
                         DataTextField="TeamName" DataValueField="TeamID"> 
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="HomeScore" HeaderText="Sc" />
                <asp:BoundField DataField="Away" HeaderText="Away" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:DropDownList ID="lstAwayTeams" runat="server" DataSource='<%# teams.GetAllTeams() %>'
                         DataTextField="TeamName" DataValueField="TeamID">
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="AwayScore" HeaderText="Sc" />
                <asp:ButtonField CommandName="DisplayUpdateInfo" ButtonType="Button" DataTextField="GameID" />
            </Columns>
        </asp:GridView

Here is event code

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string homeTeam = ((DropDownList)GridView1.SelectedRow.FindControl("lstHomeTeams")).SelectedValue;
    }

When I click the button "DisplayUpdateInfo" I get a null reference exception. ?? My eyes hurt

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.