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

I am trying to append databound items to my drop down list. The appending part seems to work find, however when the drop down list is being appended new items do get added to the list but the older items that were there are still seem to be staying in the list.

I have 2 drop down lists, one for database name which passes a variable to a stored procedure in sql so that it brings back a list of data to populate the drop down list that needs to be appended.

So for eg. if i select item A from down list 1 then drop down list 2 should be populated with items only for item A from drop down list one. At the moment it just keeps adding data instead of it being specific to the first drop down list.

thanks.
Posted

You are probably adding items after it is bound.
You can use
C#
DropDownList1.Items.Clear();
to remove all items from the drop down list before you add any.

Show us your code and we will be able to help better.
 
Share this answer
 
simply Clear all the item from dropdownlist before appending.
1. Dropdownlist1.item.clear();

Than add new items:
2. Dropdownlist1.item.add("item_name");
 
Share this answer
 
You can use this :

ddlAgentName.Items.Clear();
ddlAgentName.DataSource = DTBND.GetAgents(ddlDatabaseName.SelectedValue)
ddlAgentName.DataBind()
 
Share this answer
 

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