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. trouble with dropdownlist on selectedIndex property

trouble with dropdownlist on selectedIndex property

Scheduled Pinned Locked Moved ASP.NET
databasehelp
2 Posts 2 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.
  • C Offline
    C Offline
    cool_man
    wrote on last edited by
    #1

    I had a function to create one dropdownlist: CountyID Name 1 sdf 2 rfd 3 fdf 4 tgg 5 dert sub SelectCountyList(Optional key As Integer=1) dim ConnStr As String ConnStr="Data Source=localhost; Initial Catalog=dtn; User ID=; Password=;" dim myConnection As SqlConnection myConnection=New SqlConnection(ConnStr) dim sql As String sql="Select * from County order by Name" dim mySqlAdapter As SqlDataAdapter mySqlAdapter= New SqlDataAdapter(sql,myConnection) dim ds as New DataSet mySqlAdapter.Fill(ds,"County") CountyDDList.DataSource=ds.Tables("County").defaultView key=ds.Tables("County").defaultView CountyDDList.DataBind() CountyDDList.SelectedIndex = key end sub I want to create a dropdownlist with the key parameter is value in database. ex: SelectCountyList(2) mean CountyDDList will selected "rfd" in we call the function BUT with CountyDDList.SelectedIndex = key that will selected in CountyDDList position 2( not is CountyID=2 ). Anyone help me, pls....Thanks

    B 1 Reply Last reply
    0
    • C cool_man

      I had a function to create one dropdownlist: CountyID Name 1 sdf 2 rfd 3 fdf 4 tgg 5 dert sub SelectCountyList(Optional key As Integer=1) dim ConnStr As String ConnStr="Data Source=localhost; Initial Catalog=dtn; User ID=; Password=;" dim myConnection As SqlConnection myConnection=New SqlConnection(ConnStr) dim sql As String sql="Select * from County order by Name" dim mySqlAdapter As SqlDataAdapter mySqlAdapter= New SqlDataAdapter(sql,myConnection) dim ds as New DataSet mySqlAdapter.Fill(ds,"County") CountyDDList.DataSource=ds.Tables("County").defaultView key=ds.Tables("County").defaultView CountyDDList.DataBind() CountyDDList.SelectedIndex = key end sub I want to create a dropdownlist with the key parameter is value in database. ex: SelectCountyList(2) mean CountyDDList will selected "rfd" in we call the function BUT with CountyDDList.SelectedIndex = key that will selected in CountyDDList position 2( not is CountyID=2 ). Anyone help me, pls....Thanks

      B Offline
      B Offline
      BammBamm
      wrote on last edited by
      #2

      Try this: CountryDDLList.SelectedIndex = CountryDDLList.Items.IndexOf(CountryDDLList.Items.FindByValue(key))

      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