Mega Code Archive

 
Categories / ASP.Net Tutorial / ASP Net Controls
 

Get selected item in DropDownList

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"  Inherits="DropDownList" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">     <title>Untitled Page</title> </head> <body>     <form id="form1" runat="server">     <div>         What is your favorite ice cream flavor?          <asp:DropDownList ID="flavors" runat="server">             <asp:ListItem>A</asp:ListItem>             <asp:ListItem>B</asp:ListItem>             <asp:ListItem>C</asp:ListItem>         </asp:DropDownList>         <br />          <asp:Button ID="btnSubmit" runat="server" Text="Click Me" />         <br />         <asp:Label ID="results" runat="server"></asp:Label></div>     </form> </body> </html> File: Default.aspx.vb Partial Class DropDownList     Inherits System.Web.UI.Page     Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click         results.Text = "You like " & flavors.SelectedItem.Text     End Sub End Class