Hi,
Can I ask if this is the preferred method of dealing with dropdownlists and setting the selected item to a specific value contained in a record. If you imagine that I have a table of clubs and to edit a club I load a ClubEdit page. Now my regions dropdown list is set to the values within a region table like so when the page loads:
Dim regionlist As SqlDataReader = Regions.GetRegions()
cboRegion.DataSource = regionlist
cboRegion.DataValueField = "RegionID"
cboRegion.DataTextField = "Region"
cboRegion.DataBind()
Now when I want to load a particular club I want to set the values in any dropdown to the values in the club table i.e. the RegionID field and Region (name) from my query results ...
'set regionlist to the current value
With cboRegion
'add a default item to the dropdown
cboRegion.Items.Insert(0,"")
cboRegion.SelectedIndex = 0
.SelectedItem.Value = dr("RegionID")
.SelectedItem.Text = dr("Region")
End With
I find that if I do not use the
cboRegion.Items.Insert(0,"") ...etc
bit I simply end up overwriting the first item in the list so my dropdown contains all the items minus one.
So what I am asking is .... is this how you great wise ones deal with this??
Tips and tricks for my arsenal gratefully recieved.
Laura D