Collection of Profiles

J

Jeff

Hey

asp.net 2.0

I want to populate a GridView with the profile properties off all users
registered on a website!

For example like this:
<profile enabled="true">
<properties>
<add name="FirstName" type="string"/>
<add name="LastName" type="string"/>
<add name="Gender" type="string"/>
<add name="BirthDate" type="DateTime"/>
</properties>
<profile>

Creating a GridView displaying the columns FirstName, LastName, Gender and
BirthDate...

My problem is that I don't know how to get the collection profiles.. The
only solution I can think of using a foreach loop on the MembershipUser
objects in MembershipUserCollection and create a ProfileCommon object for
each item in the MembershipCollection..:

List<ProfileCommon> profileList = null;
private MembershipUserCollection allUsers = Membership.GetAllUsers();
foreach (MembershipUser user in allUsers) {
ProfileCommon profile = Profile.GetProfile(user.UserName);
profileList.add(profile)
}
GridView1.DataSource = profileList;
GridView1.DataBind()

(I haven't tested the code above in visual studio 2005, so I'm not sure if
it compiles. I just wrote the code above to show what I whould do to get the
collection of profiles)

Isn't there a better way of doing this?

Jeff
 
M

Mark Fitzpatrick

If you want to get all the profiles, you should be able to retrieve all the
proviles through the ProfileManager.GetAllProfiles() method, which will
return a ProfileInfoCollection. I haven't tried binding this to a grid, but
I believe this could work.
 
J

Jeff

Hey

I thought the same, but it doesn't quite work. Below is the code I tryed, it
crashes because "FirstName" isn't a property of ProfileInfo (it's one of the
properties specified in web.config in the profile section). I'm also
thinking that ProfileManager.GetAllProfiles returns a
ProfileMemberCollection, which contains a collection of ProfileInfo
objects.. I've been reading a bit here and see those custom properties is
available via the ProfileCommon class, but I don't know how to get a
collection of the ProfileCommon objects...

Any suggestions?

<asp:gridview ID="gvwUsers" runat="server" autogeneratecolumns="false" >
<Columns>
<asp:ButtonField HeaderText="UserName" DataTextField="UserName" />
<asp:ButtonField HeaderText="FirstName" DataTextField="FirstName" />
</Columns>
</asp:gridview>

protected void Page_Load(object sender, EventArgs e)
{
gvwUsers.DataSource =
ProfileManager.GetAllProfiles(ProfileAuthenticationOption.Authenticated);
gvwUsers.DataBind();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

ASP.NET Profiles in WinForms 0
Profiles 0
Profiles & Membership 0
Profiles 1
Profiles problem 0
Profiles in Asp.net 2
NEWBIE: problem populating a GridView 1
How to use multiple profiles 1

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,698
Latest member
LydiaHalle

Latest Threads

Top