ASP.Net/Language Basics/Select

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Select the value of asp:DropDownList Selected Item

   <source lang="csharp">

<%@ Page Language="VB" %> <script runat="server">

   Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
     Select Case DropDownList1.SelectedItem.Value
       Case 0: Label1.Text = String.Empty  " Reset the Label1.Text
       Case 1: Label1.Text = "You got Grade E!"
       Case 2: Label1.Text = "You got Grade D!"
       Case 3: Label1.Text = "You got Grade C!"
       Case 4: Label1.Text = "You got Grade B!"
       Case 5: Label1.Text = "You got Grade A!"
     End Select
   End Sub

</script> <html> <head> </head> <body>

   <form runat="server">

<asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"> <asp:ListItem Value="0" Selected="True">- Please select a range of score -</asp:ListItem> <asp:ListItem Value="1">0 - 20</asp:ListItem> <asp:ListItem Value="2">21 - 40</asp:ListItem> <asp:ListItem Value="3">40 - 60</asp:ListItem> <asp:ListItem Value="4">61 - 80</asp:ListItem> <asp:ListItem Value="5">81 - 100</asp:ListItem> </asp:DropDownList>

<asp:Label id="Label1" runat="server"></asp:Label>

   </form>

</body> </html>

      </source>