Search

Friday, September 20, 2013
0 comments

How to remove selected item from ListBox in ASP.NET

10:11 PMFriday, September 20, 2013

<%@ 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

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top