<asp:GridView ID="grdPhones" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None"> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <Columns> <asp:CommandField ShowEditButton="True" /> <asp:CommandField ShowDeleteButton="True" /> <asp:TemplateField HeaderText="Phone Type"> <ItemTemplate> <asp:DropDownList ID="ddlType" runat="server"></asp:DropDownList> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="cNumber" HeaderText="Phone Number" /> <asp:BoundField DataField="iPhone_id" Visible="False" /> </Columns> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> <EditRowStyle BackColor="#999999" /> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> </asp:GridView>I want to populate the dropdown list in the phone types column using this code:
protected void grdPhones_RowDataBound(object sender, GridViewRowEventArgs e) { DropDownList ddl = (DropDownList)e.Row.FindControl("ddlType"); OleDbConnection Conn = new OleDbConnection(); Conn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]; Conn.Open(); // Populate the dropdown list for the phone types column String lcSQL = "SELECT Lu_Desc, iDtl_id FROM Lookup_dtl WHERE iHdr_id = 1"; OleDbDataAdapter daTypes = new OleDbDataAdapter(lcSQL, Conn); DataSet dsTypes = new DataSet(); daTypes.Fill(dsTypes); ddl.DataSource = dsTypes; ddl.DataTextField = "lu_desc"; ddl.DataValueField = "iDtl_id"; ddl.DataBind(); }But it is failing on this line: