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


27 comments:

  1. Great tutorial. Thanks for sharing :)

    ReplyDelete
  2. 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
  3. Nice Information,, Thanks for share

    ReplyDelete
  4. Good article, keep sharing with us.

    ReplyDelete
  5. bahut hi badhiya information, thanks for sharing

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

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

    ReplyDelete
  8. VERY GOOD tutorial. Thanks U for sharing

    ReplyDelete
  9. Really helpful codes you shared with us

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

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

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

    ReplyDelete
  13. Thank you for this information. i was looking for it and here i found something similar....

    ReplyDelete
  14. Excellent post, it was very helpful. Would like to see more stuff like this. Good Regards Clashmod.

    ReplyDelete
  15. Thanks for the detailed article on this topic. I would like to see more such awesome articles from you.

    ReplyDelete
  16. Thanks for the detailed article on this topic. I would like to see more such awesome articles from you.

    ReplyDelete
  17. Hi, Thank you for this info post keep share with us.

    ReplyDelete