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