remove selected item from dropdownlist - Free Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server,WCF,Entity framework snippets and tutorial remove selected item from dropdownlist

In this article I am going to explain how to remove the selected item from dropdownlist in using C#,


HTML Markup:
<asp:DropDownList ID="ddlItems" runat="server" AutoPostBack="True" CssClass="dropdownlist" onselectedindexchanged="ddlItems_SelectedIndexChanged">
         <asp:ListItem Selected="True" Value="-1">--Select Item--</asp:ListItem>
            <asp:ListItem>Item 1</asp:ListItem>
            <asp:ListItem>Item 2</asp:ListItem>
            <asp:ListItem>Item 3</asp:ListItem>

            <asp:ListItem>Item 4</asp:ListItem>
            <asp:ListItem>Item 5</asp:ListItem>             

Write the below given code on SelectIndexchanged event of Dropdownlist

C# code:
protected void ddlItems_SelectedIndexChanged(object sender, EventArgs e)
        ddlItems.Items.FindByText(ddlItems.SelectedItem.Text).Enabled = false;
    } Code:
Protected Sub ddlItems_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ddlItems.SelectedIndexChanged
        ddlItems.Items.FindByText(ddlItems.SelectedItem.Text).Enabled = False
    End Sub

What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.

Share this

Share on FacebookTweet on TwitterPlus on Google+


Great tutorial. Thanks for sharing :)

Thanks for your valuable feedback.... Keep visiting for more article.

Its very interesting and informative post
Thanks for sharing keep up the Good work

Thanks for your valuable feedback. Keep visiting for more articles.

Nice Information,, Thanks for share