View Single Post
  #1 (permalink)  
Old August 5th, 2009, 08:19 AM
tomche tomche is offline
Authorized User
Points: 297, Level: 5
Points: 297, Level: 5 Points: 297, Level: 5 Points: 297, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote