The results of my Try It Out exercise on Chap 4 are not like that in the book. I am getting the printout of what what checked and/or selected only once so it is giving me only the last item checked instead of all the items selected/checked.
This makes sense because I am only printing it out to one label. Is this really the way you designed this exercise to work?
Here is my code.
Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ListControls.aspx.vb" Inherits="Demos_ListControls" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownListLanguage" runat="server" AutoPostBack="True">
<asp:ListItem>C#</asp:ListItem>
<asp:ListItem>Visual Basic</asp:ListItem>
<asp:ListItem>CSS</asp:ListItem>
</asp:DropDownList>
<asp:CheckBoxList ID="CheckBoxListLanguage" runat="server">
<asp:ListItem>C#</asp:ListItem>
<asp:ListItem>Visual Basic</asp:ListItem>
<asp:ListItem>CSS</asp:ListItem>
</asp:CheckBoxList>
<asp:Button ID="ButtonDone" runat="server" Text="Done" />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
Code:
Partial Class Demos_ListControls
Inherits System.Web.UI.Page
Protected Sub ButtonDone_Click(sender As Object, e As System.EventArgs) Handles ButtonDone.Click
Label1.Text = "In the DDL you selected " & DropDownListLanguage.SelectedValue & "<br />"
For Each item As ListItem In CheckBoxListLanguage.Items
If item.Selected Then
Label1.Text = "In the CBL you selected " & item.Value & "<br />"
End If
Next
End Sub
End Class