Sunday, 21 October 2012

List Box - ASP.NET Toolbox



here the code below(.aspx)

<%@ 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)
    {//insert
        ListBox1.Items.Add(TextBox1.Text);
        TextBox1.Text = "";
    }
 protected void Button2_Click(object sender, EventArgs e)
    {//delete
        //or u may use this code only "ListBox1.Items.Remove(ListBox1.Text);"
        string str = ListBox1.SelectedItem.ToString();
        ListBox1.Items.Remove(str);
    }

    protected void Button3_Click(object sender, EventArgs e)
    {//update
        int i = ListBox1.SelectedIndex;
        ListBox1.Items.Insert(i, TextBox1.Text);
        ListBox1.Items.RemoveAt(i + 1);
        TextBox1.Text = "";
   

    }

    protected void Button4_Click(object sender, EventArgs e)
    {//clear
        ListBox1.Items.Clear();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div style="height: 427px">

        &nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;
        <asp:ListBox ID="ListBox1" runat="server" Height="191px" Width="167px">
        </asp:ListBox>
&nbsp;&nbsp;
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="INSERT" />
&nbsp;&nbsp;<asp:TextBox ID="TextBox1" runat="server"
            style="z-index: 1; left: 228px; position: absolute; top: 120px; margin-bottom: 0px"></asp:TextBox>
        &nbsp;
        <asp:Button ID="Button2" runat="server" Text="DELETE" onclick="Button2_Click" />
&nbsp;&nbsp;&nbsp;
        <asp:Button ID="Button3" runat="server" Text="UPDATE" onclick="Button3_Click" />
&nbsp;&nbsp;&nbsp;
        <asp:Button ID="Button4" runat="server" Text="CLEAR" onclick="Button4_Click" />

    </div>
    </form>
</body>
</html>

No comments:

Post a Comment

Tech N Science © 2013