Get selected value from a combobox and display (C#) : ComboBox « Asp Control « ASP.Net






Get selected value from a combobox and display (C#)

<%@ Page Language="c#" %>
<script runat="server">

    void Page_Load()
    {
      if(Page.IsPostBack)
        lblMessage.Text = "You have selected " + DropList1.SelectedItem.Value;
    }

</script>
<html>
    <head>
    </head>
    <body>
        <form runat="server">
        <asp:DropDownList ID="DropList1" runat="server">
        <asp:listitem>apple</asp:listitem>
        <asp:listitem>banana</asp:listitem>
        <asp:listitem>carrot</asp:listitem>
        <asp:listitem>durian</asp:listitem>
        </asp:DropDownList><br/>
        <asp:Button runat="server" Text="Button"></asp:Button><br/>
        <asp:Label ID="lblMessage" runat="server"/>
        </form>
    </body>
</html>
           
       








Related examples in the same category

1.Set static value for a combobox (asp:dropdownlist) (VB.net)
2.Get selected item from a ComboBox and check its value (VB.net)