Asp.net remove selected item from dropdownlist

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


Implementation:

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>             
        </asp:DropDownList>

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;
    }

VB.net 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


Post a Comment

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

[blogger]

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget