469,649 Members | 1,400 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,649 developers. It's quick & easy.

Setting DropDownList selectedItem from database values

I'm loading a dropdownlist control from values in a
database.... after I load the drop down, I need to set
the selecteditem to another database value... when I do
this the drop down has an additional value added to the 0
position rather than setting the proper value.
Jul 19 '05 #1
1 3812
You need to set the selected SelectedIndex property. A way
to do this if you don't know which item it is at design
time is the following:

'If your item is a string object.
dim tmpListItem as System.Web.UI.WebControls.Listitem
tmpListItem = ddlMyDropDownList.FindByText("StringValue")
'Make sure it found what you were looking for.
if not tmpListItem is Nothing then
ddlMyDropDownList.SelectedIndex = _
tmpListItem.Items.IndexOf(tmpListItem)
end if

Hope this helps.
-----Original Message-----
I'm loading a dropdownlist control from values in a
database.... after I load the drop down, I need to set
the selecteditem to another database value... when I do
this the drop down has an additional value added to the 0
position rather than setting the proper value.
.

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Frank Rocco | last post: by
5 posts views Thread by DC Gringo | last post: by
1 post views Thread by m3ckon | last post: by
4 posts views Thread by ^MisterJingo^ | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.