Last post Apr 30, 2012 08:13 PM by dotnetdev2010
Apr 30, 2012 06:33 PM|TonyLoco23|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 06:42 PM|dotnetdev2010|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 07:30 PM|texx|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 08:13 PM|dotnetdev2010|LINK
o snap, i forgot about that. Texx's post should work for you.