Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 19th, 2012, 06:56 AM
Registered User
 
Join Date: Nov 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chap 4 List Controls

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
 
Old November 25th, 2012, 04:14 PM
Registered User
 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb Re: Missing Ampersand sign

Missing &= here, you have only the = sign for the Label1.Text for the CheckBoxList. Try it like this:

Code:
...

      If item.Selected Then
        Label1.Text &= "In the CBL you selected " & item.Value & "<br />"
      End If

...
Hope this helps!

- toughdev





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chap 9 - markup for Controls jkoyle BOOK: Beginning ASP.NET 4 : in C# and VB 7 June 23rd, 2011 12:07 PM
Chap. 5, Confusion: Tying Controls to Models mprogers BOOK: Beginning Ruby on Rails 3 December 12th, 2008 03:13 AM
Chap 17 error: only content controls... Torq BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 0 September 8th, 2007 10:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.