Hello,
There are a couple of ways to create custom profile data types.
1.) To create a custom profile data type to store multiple string values, you first need to create a class that inherits from ProfileBase that defines your profile properties in the App_Code folder. The class should look like this:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Web.Profile;
public class CustomProfileClass : ProfileBase
{
public CustomProfileClass() {}
public List<String> Models
{
get { return (List<String>)base["Models"]; }
set { base["Models"] = value; }
}
}
2.) To create any other custom profile data types that would like to your web.config. Notice the inherite attributes points to your custom profile class.
<profile enabled="true" defaultProvider="AspNetSqlProfileProvider" inherits="CustomProfileClass">
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ASPNETMembershipDB" applicationName="/" />
</providers>
<properties>
<add name="DisplayName" type="string" allowAnonymous="true" />
<add name="ContactEmail" type="string" allowAnonymous="true" />
</properties>
</profile>
You should now notice that the Profile object shows your custom data types in Intellisense. You can add values to the custom data types similar to:
Profile.DisplayName = this.txtDisplayName.Text;
Profile.ContactEmail = this.txtContactEmail.Text;
foreach (ListItem item in lbxModels.Items)
{
if (item.Selected == true)
Profile.Models.Add(item.Value);
}
Thanks,
Andrew
Check out my new blog at
blog.sitelife.com/themaddblogger