Home   Cover Cover Cover Cover
 

DropDownList


From Section 6.4.10 of the book

This example shows how to build a DropDownList from statically specified list items. The items denote countries. If an item is selected the international car code of this country is displayed. As with a ListBox the items of a DropDownList can also be added dynamically or retrieved from a database.

DropDownList.aspx
<%@ Page Language="C#" %>
<html>
  <head>
    <script Language="C#" Runat="server">
      void HandleSelect(object sender, EventArgs e) {
        lab.Text = "The selected country has the international car code ";
        if (list.SelectedItem != null) lab.Text += list.SelectedItem.Value;
      }
    </script>
  </head>
  <body>
    <form Runat="server">
      <asp:DropDownList ID="list" OnSelectedIndexChanged="HandleSelect"
        AutoPostBack="true" Runat="server" >
        <asp:ListItem Text="United States" Value="USA" />
        <asp:ListItem Text="Great Britain" Value="GB" />
        <asp:ListItem Text="Germany" Value="D" />
        <asp:ListItem Text="France" Value="F" />
        <asp:ListItem Text="Italy" Value="I" />
      </asp:DropDownList><br>
      <asp:Label ID="lab" Runat="server" />
    </form>
  </body>
</html>

Try it

   http://dotnet.jku.at/book/samples/6/DropDownList.aspx