Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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 August 5th, 2009, 08:19 AM
Authorized User
 
Join Date: Apr 2009
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chap 16 pg 570 System.Collections.Generic has some invalid arguments

Hello,

I get the following error message after typing in the code for the Try It Out on pg 570.

List<int> ProfileCommon.FavouriteGenres


Error:
The best overloaded method match for 'System.Collections.Generic.List<int> .Add(int) has some invalid arguments


This occurs under the following line

Profile.FavouriteGenres.Add(Convert.ToInt32{myItem .Value));

My MyProfile.aspx.cs file looks like this

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class MyProfile : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
txtFirstName.Text = Profile.FirstName;
txtLastName.Text = Profile.LastName;
txtDateOfBirth.Text = Profile.DateOfBirth.ToShortDateString();
txtBio.Text = Profile.Bio;
}

}
protected void btnSave_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
Profile.FirstName = txtFirstName.Text;
Profile.LastName = txtLastName.Text;
Profile.DateOfBirth = DateTime.Parse(txtDateOfBirth.Text);
Profile.Bio = txtBio.Text;
Profile.FavouriteGenres.Clear();
foreach (ListItem myItem in CheckBoxList1.Items)
{
if (myItem.Selected)
{
Profile.FavouriteGenres.Add(Convert.ToInt32{myItem.Value));
}
}
}
}
}
protected void CheckBoxList1_DataBound(object sender, EventArgs e)
{
foreach (ListItem myItem in CheckBoxList1.Items)
{
int currentValue = Convert.ToInt32(myItem.Value);
if (Profile.FavouriteGenres.Contains(currentValue))
{
myItem.Selected = true;
}
}
}
}
Are there any words of wisdom out there?

Cheers

Thomas
 
Old August 5th, 2009, 08:58 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

What version / language of the book are you using? In my version there's no code on page 570. Can you provide more information?

The code you posted (List<int> ProfileCommon.FavouriteGenres) doesn't look good but I don't know what it should be exactly as I don't know what exercise you're in.

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!
 
Old August 6th, 2009, 07:42 AM
Authorized User
 
Join Date: Apr 2009
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,
I am programming in c# and the code is actually on pg 572 but begins on page 570.

Regards

Thomas
 
Old August 6th, 2009, 08:00 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It could be me, but I don't see anything that looks like

List<int> ProfileCommon.FavouriteGenres

on that page. There's no List<int> there....

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!
 
Old August 6th, 2009, 08:10 AM
Authorized User
 
Join Date: Apr 2009
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Imar,

I am glad you said that and not me because I couldn't see it in the code I posted above.

Do you know what that error message generally refers to?

Cheers

Thomas
 
Old August 6th, 2009, 08:41 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Ah, now I understand. The error message you posted didn't look like an error message so I thought it was code you typed in....

That brought me to this:

Profile.FavouriteGenres.Add(Convert.ToInt32{myItem .Value));


See that { that should be a ( ?

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!
 
Old August 6th, 2009, 09:29 AM
Authorized User
 
Join Date: Apr 2009
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you Imar.

I shouldn't really come to you with questions that have answers as simple as that.

That wrox!

Thome
 
Old August 6th, 2009, 10:08 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're welcome....

The compiler isn't giving a too helpful error here, so I can imagine the confusion...

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 16 pg 562 MyProfile does see web.config tomche BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 7 July 28th, 2009 10:47 AM
Pg 16 Green Arrow? Astrocloud BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 5 March 17th, 2008 09:34 AM
Chap 16 example not working John Cook BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 2 February 10th, 2006 05:40 PM
chapter 16 pg 570 andrewajp002 BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 3 February 5th, 2006 07:16 PM
Problem with generic collections demitry Visual Studio 2005 1 November 21st, 2005 05:30 PM





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