Can't Bind a ListBox in a DataGrid

elite-x

New Member
The error I am getting is:<BR>Object reference not set to an instance of an object. <BR><BR>I am trying to find the ListBox in the DataGrid and then Bind the data.<BR><BR>When I comment out lines 3 and 4 it does not give any errors but the data is not in the ListBox.<BR><BR>In my Sub MyDataGrid_Edit:<BR><BR>Line 1: Dim CourseTypeListBox as ListBox = MyDataGrid.Items(2).FindControl("edit_CourseType") <BR>Line 2: oCommand = New OleDbCommand("select * from R_CourseAccountsTypes", oConnection)<BR>'You must open the connection before populating the DataReader<BR> oCommand.Connection.Open() <BR>'Assign the DataSource property directly to the result<BR> 'of the ExecuteReader method.<BR><BR>Line 3: CourseTypeListBox.DataSource = oCommand.ExecuteReader(CommandBehavior.CloseConnec tion)<BR>Line 4: CourseTypeListBox.DataBind()<BR>Line 5: oCommand.Connection.Close()<BR><BR><BR>In MyDataGrid:<BR><BR><asp:TemplateColumn HeaderText="Course Type" SortExpression="CourseType"><BR> <ItemTemplate> <BR> <asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CourseType") %>'/><BR> </ItemTemplate><BR> <EditItemTemplate> <BR> <asp:ListBox id="edit_CourseType" runat="server" Rows="1" DataTextField="Type" DataValueField="Type" /> <BR> </EditItemTemplate><BR> </asp:TemplateColumn><BR><BR>Thank you<BR>Aaron<BR>
 
Back
Top