CH 17 Storing Genre Preferences in the Profile
Completed this and ran it. However, I get a build error as below:
Code:
Error 1 The type or namespace name 'Collection' does not exist in the namespace 'System' (are you missing an assembly reference?) c:\Users\Admin\AppData\Local\Temp\Temporary ASP.NET Files\clientmanagertest\9bf60365\afcf33db\App_Code.cessscad.1.cs
Here is my code behind: (I am using FavoriteIssues instead of FavoriteGenres)
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 UserProfile : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
FirstName.Text = Profile.FirstName;
LastName.Text = Profile.LastName;
DateOfBirth.Text = Profile.DateOfBirth.ToShortDateString();
Bio.Text = Profile.Bio;
}
}
protected void SaveButton_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
Profile.FirstName = FirstName.Text;
Profile.LastName = LastName.Text;
Profile.DateOfBirth = DateTime.Parse(DateOfBirth.Text);
Profile.Bio = Bio.Text;
//Clear the existing list
Profile.FavoriteIssues.clear();
//Now add the selected Issues
foreach (ListItem myItem in PreferenceList.Items)
{
if (myItem.Selected)
{
Profile.FavoriteIssues.Add(Convert.ToInt32(myItem.Value));
}
}
}
protected void PreferenceList_DataBound(object sender, EventArgs e)
{
foreach (ListItem myitem in PreferenceList.Items)
{
int currentValue = Convert.ToInt32(myitem.Value);
if (Profile.FavoriteIssues.contains(currentValue))
{
myitem.Selected = true;
}
}
}
And Web Config:
Code:
<profile>
<properties>
<add name="FirstName" />
<add name="LastName" />
<add name="DateOfBirth" type="System.DateTime" />
<add name="Bio" />
<add name="FavoriteIssues" type="System.Collection.Generic.List`1[System.Int32]" />
</properties>
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
</profile>