Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. OnselectedIndexChanged causing a NullReferenceException

OnselectedIndexChanged causing a NullReferenceException

Scheduled Pinned Locked Moved ASP.NET
databasehelpquestion
1 Posts 1 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samflex
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups