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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using dynamic dropdownlist 1

Status
Not open for further replies.

jimberger

Programmer
Jul 5, 2001
222
0
0
GB
Hello all,

I am trying to create a dynamic dropdownlist in asp.net.

using the following code

for (int i=DateTime.Now.Year-90;i<DateTime.Now.Year-15;i++)
{
li = new ListItem(i.ToString(),i.ToString());
drpDOByear.Items.Add(li);
}

However, I want to make it so that the value 1950 is the "selected" value. How do i do this dymamically?

Thanks for your help
 
There are many ways, one of which is to use the FindByValue method e.g.
Code:
myListBox.SelectedItem = myListBox.Items.FindByValue("1950");


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Hi,

thank for your posting however I get a "property cannot be assinged - it is read only" error message.
any ideas?
thanks for your help
 
Sorry, that was me being dumb! Try:
Code:
myListBox.Items.FindByText("1950").Selected = true;


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top