How to use DropDownList Control 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 Page_Load(object sender, EventArgs e)
    {
        DropDownList1.Items.Add("Apple");
        DropDownList1.Items.Add("mango");
        DropDownList1.Items.Add("orange");
     
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Label1.Text = "your selected item is <br/>" + DropDownList1.SelectedItem.Text;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server" Height="20px"
            onselectedindexchanged="DropDownList1_SelectedIndexChanged" Width="186px"
            AutoPostBack="True">
        </asp:DropDownList><br />
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    </div>
    </form>
</body>
</html>

Output
Example of Add item to DropdownList in ASP.NET

How to use DropDownList Control in ASP.NET How to use DropDownList Control in ASP.NET Reviewed by Jacob Lefore on September 27, 2013 Rating: 5

No comments