Click here to Skip to main content
15,868,127 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a weird issue on one drop down list.
It has databound items and is dependant on another dropdownlist.
So if I select a value from the 1st dropdown list then this dropdownlist in question will have databound items.

the issue that I am having is that I want to add a value at index 0 that says "ALL" and there after display the databound items but this is not working. I have it working for the rest of the dropdowns beside this 1.

here is my code:

C#
ddlPromoSuffEdit.Items.Clear();
ddlPromoSuffEdit.Items.Add(new ListItem("All", "")); //this is not being added in but data items are populated
ddlPromoSuffEdit.DataSourceID = "";
ddlPromoSuffEdit.DataSource = odsPromoSuffEdit.Select();
ddlPromoSuffEdit.DataBind();
Posted

1 solution

Hi,

If you DataBind() your list before inserting the new ListItem you should find it will display as requested.

Something like this should work:
C#
ddlPromoSuffEdit.Items.Clear();
ddlPromoSuffEdit.DataSourceID = "";
ddlPromoSuffEdit.DataSource = odsPromoSuffEdit.Select();
ddlPromoSuffEdit.DataBind();
//Insert new ListItem ... 
ddlPromoSuffEdit.Items.Insert(0, (new ListItem("All", "")));


... hope it helps.
 
Share this answer
 
Comments
Perfect. Take a 5. :)
hypermellow 15-Apr-15 7:35am    
... thank you! :-)
Welcome. :)
Then you have other issue. Please debug and watch the items after this code.
Kats2512 15-Apr-15 8:01am    
ok debugged and found the issue. this worked well. 5 star!!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900