Click here to Skip to main content
15,883,938 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
I am using 2 dropdownlist in which i added same items....wen i click item in 1st dropdownlist i want that particular item not to be displayed in the second dropdownlist...plz help regarding this....



Regards

Manohara r
Posted
Updated 1-Nov-17 23:58pm
Comments
AmitGajjar 25-Jan-12 4:24am    
post your code here...

C#
ListItem itm=dropdownlist2.Items.FindByValue(firstdropdownlistValue);
if(itm!=null)
{
dropdownlist2.Items.Remove(itm);
}
 
Share this answer
 
v2
Comments
Manohar_manu 25-Jan-12 5:15am    
hi i it is working fine for one condition..i ll you explaining detail..

my first dropdownlist is

<asp:DropDownList ID="dpscurrency" runat="server"
>
<asp:ListItem>-Select-
<asp:ListItem Value="0">LR
<asp:ListItem Value="1">EDB


and 2nd drop downlist
<asp:ListItem>-Select-
<asp:ListItem Value="0">LR
<asp:ListItem Value="1">EDB



when i select LR from dllist1 i dont want LR to be displayed in 2nd dllist2..
your solution is not working when I select EDB from 1st dlist LR was remove this should happened..it should be there when select EDB...

regards ,
manohar
C#
int count = DropDownList.Items.Count - 1;
for (int i = count; i > 0; i--)
    DropDownList.Items.RemoveAt(i);
 
Share this answer
 
ListItem itemToRemove = myDropDown.Items.FindByValue("value");
if (itemToRemove != null)
{
    myDropDown.Items.Remove(itemToRemove);
}
Or if you know the index of the item to remove, use RemoveAt method :

myDropDown.Items.RemoveAt(0);
 
Share this answer
 
C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
      {
          if (DropDownList1.SelectedItem.ToString() == "One")
          {
              DropDownList2.Items.Remove("One");
          }
          else
          {
              DropDownList2.Items.Add("One");
          }
      }
 
Share this answer
 
Comments
Manohar_manu 27-Jan-12 1:32am    
very nice
Sergey Alexandrovich Kryukov 2-Jul-13 0:50am    
You are "answering" your own question and tell to yourself "very nice". It it cheating or what?
—SA

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