Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi In DropdownList 10 values are there that values are came from Database,How to remove one value in that dropdownlist.
Posted

DropDownList1.Items.RemoveAt(index);
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Feb-11 1:07am    
Slightly different the answer... that is funny OP accepted just one.
--SA
m@dhu 7-Feb-11 1:31am    
You know about most of the newbies they wants the exact code rather than trying something so he did marked it.
Sergey Alexandrovich Kryukov 7-Feb-11 2:18am    
Huh you got it.
Espen Harlinn 7-Feb-11 15:45pm    
Nice and simple, a 5
What, System.Web.UI.WebControls.DropDownList.Items.Remove is your problem?!

—SA
 
Share this answer
 
Comments
JF2015 7-Feb-11 0:41am    
The most simple answers are sometimes the best ones.
Sergey Alexandrovich Kryukov 7-Feb-11 0:43am    
Thank you, JF2015, I just saw, OP answered "yes", as if it is a problem. Removed, probably...
--SA
Abhinav S 7-Feb-11 1:16am    
I saw your answer. Just added mine with the item included so that it makes more sense for the OP.
Espen Harlinn 7-Feb-11 15:44pm    
Nice and simple, a 5
Sergey Alexandrovich Kryukov 7-Feb-11 21:52pm    
Thank you, Espen.

And thank you OP for finally accepting my answer :-)
--SA
C#
Dropdownlist1.Items.Remove(Dropdownlist1.Text);
// rimuove l'elemento selezionato al momento...


[edit]pre tag for C# code added - PES [/edit]
 
Share this answer
 
v2
Try
MIDL
DropDownList1.Items.Remove("Item");
 
Share this answer
 
C#
int i=Dropdownlist1.Items.count;
for(int j=0;j<i;j++)>
{
    if(Dropdownlist1.Items[j].selected==true)
    {
        Dropdownlist1.Items.Remove(Dropdownlist1.Items[i].toString();
        i--;
    }
}


[edit]pre tag for C# code added - PES [/edit]
 
Share this answer
 
v2
Well,

there are 2 Approaches:

contol: asp drop down list.
C#
event: protected void drop_downList1_SelectedIndexChanged(object sender, EventArgs e)
{

}





protected void drop_downList1_SelectedIndexChanged(object sender, EventArgs e)
{

  string selectedSub = ddlRepetsub1.SelectedItem.Text;

  drop_downList2.Items.FindByText(selectedSub).Enabled = false;

}



protected void drop_downList1_SelectedIndexChanged(object sender, EventArgs e)
{
   string selectedSub = ddlRepetsub1.SelectedItem.Text; 

   drop_downList2.Items.Remove(selectedSub);

}
 
Share this answer
 
Comments
[no name] 10-Sep-14 8:18am    
Do you really think that the OP was really waiting 3 years for another answer to an already answered question?
4K5H4Y 11-Sep-14 2:40am    
@Wes Aday, My intention was to improve the quality of answer. Google still shows link for the questions. I hope it will be helpful to others who visit here. Thanks by the way !

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