Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binding a Dropdown List 2

Status
Not open for further replies.

Fubear

IS-IT--Management
Sep 11, 2002
299
GB
I have a dropdown list that lists all the records in a table. I can bind the datasource so that it puls out the right data and displays the list items correctly.

What I am trying to do is set it so that the selected value is set to the value in the currently selected record. I can only see options for binding the list items, not the actual value the list has as a default. I dont want to have to do this in code if it can be avoided.
 
You have to loop through the item collection for the dropdown list and when you find the value of the item that matches the value that is in the database you then set that item to be selected either by the selectedindex property of selecteditem property.

James :)


James Culshaw
james@miniaturereview.co.uk
 
If you know the default value, then you can do this:
myDropDownList.SelectedValue = "999";
 
Oops, I just posted a much longer-winded version of your question. I don't have a selectedvalue option on the ddl. I haven't yet moved my project over to VS.NET 2003. I have to wonder if they've fixed this in the newer version. If they give you the option to set the value, they should give you the option to pull the value you set!

Let me know if you get anywhere.

Thanks!
Kimberly
 
You are right, SelectedValue property of a DropDownList control became available in Framework 1.1. Otherwise, you'll need to follow culshaja's post.
 
Well, I guess I have to do it then... I installed it months ago and I've just been too afraid to make the switch...

Thanks for the input! I hope you're right! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top