Home   Cover Cover Cover Cover


From Section 6.4.6 of the book

This example implements a shopping list in which you can click several CheckBoxes. If you click on the button, the selected items are listed on the page.

<%@ Page Language="C#" %>
    <script Language="C#" Runat="server">
      void ButtonClicked(object sender, EventArgs e) {
        label.Text = "You bought: ";
        if (apples.Checked) label.Text += "Apples ";
        if (pears.Checked) label.Text += "Pears ";
        if (bananas.Checked) label.Text += "Bananas ";
    <form Runat="server">
      <asp:CheckBox ID="apples" Text="Apples" Runat="server" /><br>
      <asp:CheckBox ID="pears" Text="Pears" Runat="server" /><br>
      <asp:CheckBox ID="bananas" Text="Bananas" Runat="server" /><br>
      <asp:Button Text="Buy" OnClick="ButtonClicked" Runat="server" />
      <asp:Label ID="label" Runat="server" />

Try it