Mayfield2268 Posted November 20, 2003 Posted November 20, 2003 I placed a drop down list in a datagrid. I want to pre-select which value in the drop down list is selected based an a value from a database. I keep getting the following error... Exception Details: System.NullReferenceException: Object variable or With block variable not set. Here is my code... Private Sub dgTest_Edit(ByVal sender As System.Object, ByVal e As DataGridCommandEventArgs) Handles dgTest.EditCommand Dim T As New DropDownList() T = CType(e.Item.FindControl("ddlTest"), DropDownList) Response.Write(T.SelectedIndex & "HELP") End Sub It seems to me that no control is found when I call FindControl resulting in the NullReferenceException. Does anyone know why this would be occuring? Thanks Jason Lee Mayfield Quote
Moderators Robby Posted November 20, 2003 Moderators Posted November 20, 2003 You need to do this in your aspx page... <asp:DropDownList id="ddlTest" runat="server" datavaluefield="my_column_id" datatextfield="my_column_text" SelectedIndex='<%# GetDD_SelectedIndex(Container.DataItem("my_column_id")) %>' DataSource="<%#myEditData%>"></asp:DropDownList> The function GetDD_SelectedIndex takes the id column and returns the selected index from the database. myEditData function returns the dataset needed to bind to this dropdown Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.