List box Control in asp.net

 For Example: Write a program to demonstrate the use of List box control.

.aspx File:

 <html>

<head runat="server">

    <title>Aryan Computers, Brshi (Listbox Control)</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

           <asp:Label ID="Label1" runat="server" Font-Bold="True"

            Font-Names="Comic Sans MS" Font-Underline="True" ForeColor="#CC0066"

            Text="List Box Control Example "></asp:Label>        

    </div>

    <asp:ListBox ID="ListBox1" runat="server">

        <asp:ListItem>BCA-I</asp:ListItem>

        <asp:ListItem>BCA-II</asp:ListItem>

        <asp:ListItem>BCA-III</asp:ListItem>

    </asp:ListBox>

    <br />

    <asp:Label ID="Label2" runat="server" Font-Bold="True"></asp:Label>

    <br />    <p>

        <asp:Button ID="Button1" runat="server" Font-Bold="True"

            onclick="Button1_Click" Text="Check Selected Course in the List" />

    </p>

    </form>

</body>

</html>

 

.aspx.cs File:

 namespace WebApplication3

{

    public partial class WebForm5 : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

 

        }

 

        protected void Button1_Click(object sender, EventArgs e)

        {

                     Label2.Text = "Your Selected Class is :  " + ListBox1.SelectedValue;

        }

    }

}

Output:



Comments

Popular posts from this blog

simple program C#

Regular Expression Validator Control in asp.net

two dimension array in C#