How to remove selected item from ListBox in ASP.NET


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (ListBox1 .Items .Count !=0)
        {
            ListBox1.Items.RemoveAt(ListBox1.SelectedIndex);
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ListBox ID="ListBox1" runat="server" Height="142px" Width="117px">
            <asp:ListItem>APPLE</asp:ListItem>
            <asp:ListItem>MANGO</asp:ListItem>
            <asp:ListItem>ORANGE</asp:ListItem>
        </asp:ListBox>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click"
            Text="REMOVE SELECTED" Width="143px" />
    </div>
    </form>
</body>
</html>

Output
Item in listbox in asp.net
How to remove selected item from ListBox in ASP.NET

How to remove selected item from ListBox in ASP.NET How to remove selected item from ListBox in ASP.NET Reviewed by Jacob Lefore on September 20, 2013 Rating: 5

No comments