How to set up dropdownlist selected value

G

Guest

Hi, I have a dropdownlist that is basically pulled the data from database
using sqldatasource.

The dropdownlist will give years result. The results will be from 1967 to
2006.

I have anoher query using sqldatasource that will give me the result of year
2004. How do I bind the second query so the dropdownlist will make 2004 as
its default selected value? RIght now, 1967 is by default the selected value.

Thanks.
 
K

Karl Seguin [MVP]

years.SelectedIndex = years.Items.IndexOf(years.Items.FindByValue("2004"))

you can also do FindByText(...)

Karl
 
T

Teemu Keiski

Hi,

get the value from the second query into a string variable. Then you can
just make the selection:

DropDownList1.SelectedIndex =
DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(<string_var_goes_here_with_value_2004>))

Yes, you can also do it in code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top