Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 30, 2012 07:13 PM by dotnetdev2010
Apr 30, 2012 05:33 PM|LINK
This is something that has been bugging me for a while.
I have a list of categories stored in a SQL Server table. I want to bind them to a drop down list. But I also want to add one additional option to the top of the list that simply says "Include All Categories" with an index of 0.
What is the simplest way to do this? Can it be done non-programmatically in the page design?
Apr 30, 2012 05:42 PM|LINK
before doing the data binding from the data base do dropdownlist.items.add("Include All Categories"). The databind my clear out any items already added if that is the case you might be better off looping through the data. So you would need to do dropdownlist.items.add("Include
All Categories") followed by a loop that adds each item from the DB. So rather than databinding you might have to read from the DB.
do while dbReader.read
i += 1
Apr 30, 2012 06:30 PM|LINK
You can leave the dropdownlist databound however you need, but after it is databound you can call
dropdownlist.items.insert(0, new ListItem("All items"));
See article from 4guysfromrolla
Apr 30, 2012 07:13 PM|LINK
o snap, i forgot about that. Texx's post should work for you.