Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old November 19th, 2012, 06:57 AM
Registered User
Points: 10, Level: 1
Points: 10, Level: 1 Points: 10, Level: 1 Points: 10, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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 was 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=""></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
  #2 (permalink)  
Old November 20th, 2012, 03:35 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

>> Is this really the way you designed this exercise to work?

Yes, that's how it's supposed to work. What you forgot was an additional plus symbol. You have this:

Code:
Label1.Text = "In the CBL you selected " & item.Value & "<br />"
This overrides the Text property of the Label on each iteration. What you need instead is this:

Code:
 
Label1.Text += "In the CBL you selected " & item.Value & "<br />"
Notice the += instead of the =. This appends the new text to the text that was already there on the label.

Chapter 5 has more examples and an explanation of this concatenation operator.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #3 (permalink)  
Old December 4th, 2012, 12:29 AM
Registered User
Points: 32, Level: 1
Points: 32, Level: 1 Points: 32, Level: 1 Points: 32, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i am unable to understand what you both are trying to explain through these codewords
  #4 (permalink)  
Old December 4th, 2012, 03:33 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

In that case, you may want to get a copy of this book as it discusses this stuff in detail.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chap 4 List Controls Workmad BOOK: Beginning ASP.NET 4 : in C# and VB 1 November 25th, 2012 04:14 PM
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.