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