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!

filling dropdown with nonbound values 2

Status
Not open for further replies.

Trusts

Programmer
Feb 23, 2005
268
0
0
US
Hi all,
I am trying to fill an ASP:DropDown control with values/data just from code. The dropdwon is just to display Yes or No. I have no table in the database with these simple values. In access you can "Add" values to a dropdown, but I don't see how to do this in asp.net 2. It seems I must use some variation of a Datasource. Is there a way to just fill the dropdown without a dedicated Datasource?

Thanks,
KB
 
You can use the Items.Insert method, or you could add a ListItem in the actual HTML portion of the control.


____________________________________________________________

Need help finding an answer?

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

 
Code:
myDll.Items.Add(new ListItem("Yes", "1"));
myDll.Items.Add(new ListItem("No", "0"));
 
You can also use the Item.Add method (as LV suggested) but still take a look at the Item.Insert method as it allows you to specify the position of where the Item is added in the collection.


____________________________________________________________

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