OnselectedIndexChanged causing a NullReferenceException
-
Greetings. This is not making a whole lot of sense to me. I have a dropdownList that is dynamically populated from the database. This works. However, I have an OnselectedIndexChanged event tied to this DropDownList that when a user selects an item from the DropDownList, an associated value is stored on a textbox. This was working when used a regular webform. However, due to the complicated nature of some other controls, I had to switch to Repeater control. Now, this
OnselectedIndexChanged event
is not working any longer. When I select a value from the DropDownList, it throws the following error: System.NullReferenceException: Object reference not set to an instance of an object, pointing to the SQL select statement line. What am I missing please?
$ Protected Sub ddlWater\_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Using con As SqlConnection = New SqlConnection(constring) Dim txt\_amount As TextBox = CType(DynamicRepeater.FindControl("txt\_amount"), TextBox) Dim dt As New DataTable() Dim ddlWater As DropDownList = CType(DynamicRepeater.FindControl("ddlWater"), DropDownList) con.Open() Dim sql As String = " SELECT RebateAmount FROM WaterVolume WHERE WaterSizes = '" & ddlWater.SelectedValue & "' " Response.Write(sql) Response.End() Dim cmd As SqlCommand = New SqlCommand(sql, con) Dim ad As SqlDataAdapter = New SqlDataAdapter(cmd) ad.Fill(dt) If dt.Rows.Count > 0 Then txt\_amount.Text = dt.Rows(0)("Amount").ToString() End If End Using End Sub
Error is on this line below:
Dim sql As String = " SELECT RebateAmount FROM WaterVolume WHERE WaterSizes = '" &
Thank you in advance