This documentation is archived and is not being maintained.

ProfileBase.Item Property

Gets or sets a profile property value indexed by the property name.

Namespace:  System.Web.Profile
Assembly:  System.Web (in System.Web.dll)

public override Object this[
	string propertyName
] { get; set; }


Type: System.String
The name of the profile property.

Property Value

Type: System.Object
The value of the specified profile property, typed as object.


An attempt was made to set a property value on an anonymous profile where the property's allowAnonymous attribute is false.


There are no properties defined for the current profile.


The specified profile property name does not exist in the current profile.


The provider for the specified profile property did not recognize the specified property.


An attempt was made to set a property value that was marked as read-only.


An attempt was made to assign a value to a property using an incompatible type.

You can use this property to retrieve or set the property values of the user profile for your application by name. Returned values are typed as object and must be cast as the specific object type when retrieved. For strongly typed access to profile property values, you can access the property by name as a member of the Profile property available on each page, for example, Profile.CustomerAddress.

The following code example lists the names of the properties in the user profile by binding the Name property from the static Properties collection of SettingsProperty objects to a GridView control. The selected property value is retrieved by name using the Item collection. For an example of a Web.config file that specifies properties for the user profile, see the example provided for the ProfileBase class.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Profile" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

public void Page_Load()
  if (!IsPostBack)
    PropertiesListBox.DataSource = ProfileBase.Properties;

  if (PropertiesListBox.SelectedItem != null)
    object propValue = Profile[PropertiesListBox.SelectedItem.Text];

    Type propType = propValue.GetType();

    // If the property is a value type, return ToString().

    if (propType == typeof(string) || propType.IsValueType)
      ValueLabel.Visible = true;
      ValueGridView.Visible = false;
      ValueLabel.Text = propValue.ToString();

    // Bind the property to a GridView.

      ValueGridView.DataSource = propValue;
      ValueGridView.Visible = true;
      ValueLabel.Visible = false; 
      // If the property is not bindable, return ToString().

      ValueLabel.Visible = true;
      ValueGridView.Visible = false;
      ValueLabel.Text = propValue.ToString();

<html xmlns="" >
<title>Home Page</title>

<h3>View Profile properties:</h3>

<form id="form1" runat="server">
  <table border="0" cellpadding="2" cellspacing="2">
      <td valign="top">
        <asp:ListBox runat="server" id="PropertiesListBox" Rows="10" AutoPostBack="True" DataTextField="Name" />
      <td valign="top">
        <asp:GridView runat="Server" id="ValueGridView" Visible="False" />
        <asp:Label runat="Server" id="ValueLabel" Visible="False" />


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.