ProfileBase.Item プロパティ
アセンブリ: System.Web (system.web.dll 内)

Dim instance As ProfileBase Dim propertyName As String Dim value As Object value = instance(propertyName) instance(propertyName) = value
public: virtual property Object^ default [String^] { Object^ get (String^ propertyName) override; void set (String^ propertyName, Object^ value) override; }
/** @property */ public Object get_Item (String propertyName) /** @property */ public void set_Item (String propertyName, Object value)
- propertyName
プロファイル プロパティの名前。
指定されたプロファイル プロパティの値。object 型として返されます。

例外の種類 | 条件 |
---|---|
System.Configuration.Provider.ProviderException | プロパティの allowAnonymous 属性が false である匿名プロファイルに対してプロパティ値を設定しようとしました。 |
System.Configuration.SettingsPropertyNotFoundException | 現在のプロファイルに対して定義されたプロパティはありません。 または 指定されたプロファイル プロパティ名が、現在のプロファイルに存在しません。 または |
System.Configuration.SettingsPropertyIsReadOnlyException | |
System.Configuration.SettingsPropertyWrongTypeException |

このプロパティを使用して、アプリケーションのユーザー プロファイルのプロパティ値を名前で取得したり、設定したりできます。戻り値は object として型指定されているため、取得時に、特定のオブジェクト型としてキャストする必要があります。型を厳密に指定してプロファイルのプロパティ値にアクセスする場合は、各ページごとに使用できる Profile プロパティのメンバ (たとえば、Profile.CustomerAddress など) として、名前でプロパティにアクセスします。

次のコード例では、SettingsProperty オブジェクトの静的な Properties コレクションからの Name プロパティを GridView コントロールにバインドすることで、ユーザー プロファイル内のプロパティ名を一覧表示します。選択されたプロパティ値を、Item コレクションを使用して名前で取得します。ユーザー プロファイルのプロパティを指定する Web.config ファイルの例については、ProfileBase クラスの例を参照してください。
<%@ Page Language="VB" %> <%@ Import Namespace="System.Web.Profile" %> <script runat="server"> Public Sub Page_Load() If Not IsPostBack Then PropertiesListBox.DataSource = ProfileBase.Properties PropertiesListBox.DataBind() End If If Not PropertiesListBox.SelectedItem Is Nothing Then Dim propValue As Object = Profile(PropertiesListBox.SelectedItem.Text) Dim propType As Type = propValue.GetType() ' If the property is a value type, return ToString(). If propType Is GetType(String) Or propType.IsValueType Then ValueLabel.Visible = True ValueGridView.Visible = False ValueLabel.Text = propValue.ToString() Return End If ' Bind the property to a GridView. Try ValueGridView.DataSource = propValue ValueGridView.DataBind() ValueGridView.Visible = True ValueLabel.Visible = False Catch ' If the property is not bindable, return ToString(). ValueLabel.Visible = True ValueGridView.Visible = False ValueLabel.Text = propValue.ToString() End Try End If End Sub </script> <html> <head> <title>Home Page</title> </head> <body> <h3>View Profile properties:</h3> <form runat="server"> <table border=0 cellpadding=2 cellspacing=2> <tR> <td>Property</td> <td>Value</td> </tR> <tr> <td valign="top"> <asp:ListBox runat="server" id="PropertiesListBox" Rows="10" AutoPostBack="True" DataTextField="Name" /> </td> <td valign="top"> <asp:GridView runat="Server" id="ValueGridView" Visible="False" /> <asp:Label runat="Server" id="ValueLabel" Visible="False" /> </td> </tr> </table> </form> </body> </html>
<%@ Page Language="C#" %> <%@ Import Namespace="System.Web.Profile" %> <script runat="server"> public void Page_Load() { if (!IsPostBack) { PropertiesListBox.DataSource = ProfileBase.Properties; PropertiesListBox.DataBind(); } 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(); return; } // Bind the property to a GridView. try { ValueGridView.DataSource = propValue; ValueGridView.DataBind(); ValueGridView.Visible = true; ValueLabel.Visible = false; } catch { // If the property is not bindable, return ToString(). ValueLabel.Visible = true; ValueGridView.Visible = false; ValueLabel.Text = propValue.ToString(); } } } </script> <html> <head> <title>Home Page</title> </head> <body> <h3>View Profile properties:</h3> <form runat="server"> <table border=0 cellpadding=2 cellspacing=2> <tR> <td>Property</td> <td>Value</td> </tR> <tr> <td valign="top"> <asp:ListBox runat="server" id="PropertiesListBox" Rows="10" AutoPostBack="True" DataTextField="Name" /> </td> <td valign="top"> <asp:GridView runat="Server" id="ValueGridView" Visible="False" /> <asp:Label runat="Server" id="ValueLabel" Visible="False" /> </td> </tr> </table> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からProfileBase.Item プロパティを検索する場合は、下記のリンクをクリックしてください。

- ProfileBase.Item プロパティのページへのリンク