Home   Cover Cover Cover Cover
 

ListBox With Statically Specified Entries


From Section 6.4.9 of the book

This example shows how to build a ListBox from statically specified list items. The items denote countries. If an item is selected the international car code of this country is displayed.

ListBox.aspx
<%@ Page Language="C#" %>
<html>
  <head>
    <script Language="C#" Runat="server">
      void ButtonClick(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:ListBox ID="list" Rows="3" Runat="server" >
        <asp:ListItem Text="United States" Value="USA" Runat="server" />
        <asp:ListItem Text="Great Britain" Value="GB" Runat="server" />
        <asp:ListItem Text="Germany" Value="D" Runat="server" />
        <asp:ListItem Text="France" Value="F" Runat="server" />
        <asp:ListItem Text="Italy" Value="I" Runat="server" />
      </asp:ListBox><br><br>
      <asp:Button OnClick="ButtonClick" Text="Show" Runat="server" /><br>
      <asp:Label ID="lab" Runat="server" />
    </form>
  </body>
</html>

Try it

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