请问高手,我想把用户配置ProfileProviders中的属性信息用GridView的方式列出来,这个是否可以实现,应该怎么做,谢谢!

解决方案 »

  1.   

    GridView1.DataSource = ProfileBase.Properties;
    GridView1.DataBind();
      

  2.   


    DataTable dt = new DataTable();
    dt.Columns.Add("UserName");

    var properties = ProfileBase.Properties.Cast<SettingsProperty>().ToList();
    properties.ForEach(property => dt.Columns.Add(property.Name));

    foreach (ProfileInfo info in ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All))
    {
    DataRow row = dt.NewRow();
    var profile = Profile.GetProfile(info.UserName);
    row["UserName"] = profile.UserName;
    properties.ForEach(property=> row[property.Name] = profile.GetPropertyValue(property.Name));
    dt.Rows.Add(row);
    } GridView1.DataSource = dt;
    GridView1.DataBind();
      

  3.   

    非常感谢你的回复,不过你的做法我有点还没弄懂,下面是我费了好大劲弄的,倒是能运行,不知这样是不是一个合理的做法?ProfileInfoCollection pic = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All);        HashSet<ProfileCommon> hs = new HashSet<ProfileCommon>();        foreach (ProfileInfo pi in pic)
            {
                ProfileCommon pc = Profile.GetProfile(pi.UserName);
                hs.Add(pc);
               
            }
            //Lbl.Text = profile.真实姓名;        this.GridView1.DataSource = hs;
            this.GridView1.DataBind();