Tuesday, February 23, 2016

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


21 comments:

  1. Great tutorial. Thanks for sharing :)

    ReplyDelete
    Replies
    1. Thanks for your valuable feedback.... Keep visiting for more article.

      Delete
  2. thanku for great informations

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

    ReplyDelete
    Replies
    1. Thanks for your valuable feedback. Keep visiting for more articles.

      Delete
  4. Nice Information,, Thanks for share

    ReplyDelete
  5. Good article, keep sharing with us.

    ReplyDelete
  6. bahut hi badhiya information, thanks for sharing

    ReplyDelete
  7. Really helpful codes you shared with us.. update with more pls

    ReplyDelete
  8. thanks for your useful information.I appreciate your work.

    ReplyDelete
  9. VERY GOOD tutorial. Thanks U for sharing

    ReplyDelete
  10. Really helpful codes you shared with us

    ReplyDelete
  11. Really helpful codes you shared with us.. update with more pls

    ReplyDelete
  12. Thanks for the detailed article, Would love to see more of these.

    ReplyDelete
  13. THank you for this great article....

    ReplyDelete