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. Error in dropdownlist binding

Error in dropdownlist binding

Scheduled Pinned Locked Moved ASP.NET
databasewpfwcfhelp
3 Posts 3 Posters 0 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.
  • M Offline
    M Offline
    mominafiz
    wrote on last edited by
    #1

    i have created drop downdownlist and i m binding it with the testnames in the database.

    Private Function load_sptestreqtestnameddl()

        Dim Adptr As New SqlDataAdapter
        Dim Pkgddldt As New DataSet
    
        '##################     FOR CONNECTION  ################
    
        Dim MySearchCon As DbConnection = providerFactory.CreateConnection()
        MySearchCon.ConnectionString = connectionString.ConnectionString
    
        '###################  END OF CONNECTION #################
    
        Dim str As String = Nothing
        str = ("SELECT test\_id, test\_name FROM TestName")
    
        Adptr = New SqlDataAdapter(str, MySearchCon)
        Adptr.Fill(Pkgddldt)
    
        sptestreqtestnameddl.DataSource = Pkgddldt
        sptestreqtestnameddl.DataSource = Pkgddldt.Tables(0)
        sptestreqtestnameddl.DataTextField = Pkgddldt.Tables(0).Columns("test\_name").ColumnName.ToString
        sptestreqtestnameddl.DataValueField = Pkgddldt.Tables(0).Columns("test\_id").ColumnName.ToString
    

    sptestreqtestnameddl.DataBind()
    Return 0
    End sub

    the code shows me following error....this exactly same code works perfect in other webforms. 'sptestreqtestnameddl' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value

    S B 2 Replies Last reply
    0
    • M mominafiz

      i have created drop downdownlist and i m binding it with the testnames in the database.

      Private Function load_sptestreqtestnameddl()

          Dim Adptr As New SqlDataAdapter
          Dim Pkgddldt As New DataSet
      
          '##################     FOR CONNECTION  ################
      
          Dim MySearchCon As DbConnection = providerFactory.CreateConnection()
          MySearchCon.ConnectionString = connectionString.ConnectionString
      
          '###################  END OF CONNECTION #################
      
          Dim str As String = Nothing
          str = ("SELECT test\_id, test\_name FROM TestName")
      
          Adptr = New SqlDataAdapter(str, MySearchCon)
          Adptr.Fill(Pkgddldt)
      
          sptestreqtestnameddl.DataSource = Pkgddldt
          sptestreqtestnameddl.DataSource = Pkgddldt.Tables(0)
          sptestreqtestnameddl.DataTextField = Pkgddldt.Tables(0).Columns("test\_name").ColumnName.ToString
          sptestreqtestnameddl.DataValueField = Pkgddldt.Tables(0).Columns("test\_id").ColumnName.ToString
      

      sptestreqtestnameddl.DataBind()
      Return 0
      End sub

      the code shows me following error....this exactly same code works perfect in other webforms. 'sptestreqtestnameddl' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value

      S Offline
      S Offline
      Shahriar Iqbal Chowdhury Galib
      wrote on last edited by
      #2

      hi, After filling the data adapter, please clear the dropdown then try to bind.

      sptestreqtestnameddl.Items.Clear();

      Seems to me after binding list, dropdown tries to select a value that is not even in the dropdown list. Thnaks

      1 Reply Last reply
      0
      • M mominafiz

        i have created drop downdownlist and i m binding it with the testnames in the database.

        Private Function load_sptestreqtestnameddl()

            Dim Adptr As New SqlDataAdapter
            Dim Pkgddldt As New DataSet
        
            '##################     FOR CONNECTION  ################
        
            Dim MySearchCon As DbConnection = providerFactory.CreateConnection()
            MySearchCon.ConnectionString = connectionString.ConnectionString
        
            '###################  END OF CONNECTION #################
        
            Dim str As String = Nothing
            str = ("SELECT test\_id, test\_name FROM TestName")
        
            Adptr = New SqlDataAdapter(str, MySearchCon)
            Adptr.Fill(Pkgddldt)
        
            sptestreqtestnameddl.DataSource = Pkgddldt
            sptestreqtestnameddl.DataSource = Pkgddldt.Tables(0)
            sptestreqtestnameddl.DataTextField = Pkgddldt.Tables(0).Columns("test\_name").ColumnName.ToString
            sptestreqtestnameddl.DataValueField = Pkgddldt.Tables(0).Columns("test\_id").ColumnName.ToString
        

        sptestreqtestnameddl.DataBind()
        Return 0
        End sub

        the code shows me following error....this exactly same code works perfect in other webforms. 'sptestreqtestnameddl' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value

        B Offline
        B Offline
        Blue_Boy
        wrote on last edited by
        #3

        Just specify columns in DataTextField and DataValueField like this:

        sptestreqtestnameddl.DataTextField = "test_name"
        sptestreqtestnameddl.DataValueField = "test_id"


        I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

        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