📄 readprofilecontinue.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//using System.Web.Profile;
using System.Drawing;
public partial class ReadProfileContinue : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadUsers(); //将用户载入到DropDownList
}
}
//将用户载入到DropDownList
private void LoadUsers()
{
//取得所有用户的集合
MembershipUserCollection Users = Membership.GetAllUsers();
//将用户的集合中的用户名加入DropDownList
foreach (MembershipUser singleUser in Users)
{
cbxUsers.Items.Add(singleUser.UserName);
}
}
//读取用户Profile配置文件数据
protected void btnReadProfiles_Click(object sender, EventArgs e)
{
int statusSelected = 0;
Panel1.Visible = true;
for (int i = 0; i < cbxUsers.Items.Count; i++)
{
if (cbxUsers.Items[i].Selected)
{
//显示用户Profile
showUser(cbxUsers.Items[i].Text);
statusSelected = 1;
}
}
//若CheckBox没有任何勾选,则隐藏Panel
if (statusSelected == 0)
{
Panel1.Visible = false;
}
}
//显示用户Profile相关信息
private void showUser(string txtUserName)
{
//取得特定用户之Profile
ProfileCommon userProfile = Profile.GetProfile(txtUserName);
if (ProfileCommon.Properties.Count >= 0)
{
DataTable dtProfile = getUserProfileTable(userProfile);
GridView gviewProfile = new GridView();
setGridViewStyle(gviewProfile); //设置GridView外观样式
gviewProfile.DataSource = dtProfile;
gviewProfile.DataBind();
Panel1.Controls.Add(gviewProfile);
}
}
//将用户Profile数据建立成DataTable后返回
private DataTable getUserProfileTable(ProfileCommon userProfile)
{
DataTable dtProfile = new DataTable();
dtProfile.Columns.Add("Profile属性名称", typeof(string));
dtProfile.Columns.Add("Profile属性值", typeof(string));
DataRow singleRow;
//用户名
singleRow = dtProfile.NewRow();
singleRow["Profile属性名称"] = "UserName";
singleRow["Profile属性值"] = userProfile.UserName;
dtProfile.Rows.Add(singleRow);
//用户性别
singleRow = dtProfile.NewRow();
singleRow["Profile属性名称"] = "Sex";
singleRow["Profile属性值"] = userProfile.Sex;
dtProfile.Rows.Add(singleRow);
//所用者所在县市
singleRow = dtProfile.NewRow();
singleRow["Profile属性名称"] = "县市";
singleRow["Profile属性值"] = userProfile.Address.City;
dtProfile.Rows.Add(singleRow);
//所用者生日
singleRow = dtProfile.NewRow();
singleRow["Profile属性名称"] = "生日";
singleRow["Profile属性值"] = userProfile.生日;
dtProfile.Rows.Add(singleRow);
//所用者学历
singleRow = dtProfile.NewRow();
singleRow["Profile属性名称"] = "学历";
singleRow["Profile属性值"] = userProfile.Sex;
dtProfile.Rows.Add(singleRow);
//所用者星座
singleRow = dtProfile.NewRow();
singleRow["Profile属性名称"] = "星座";
singleRow["Profile属性值"] = userProfile.星座;
dtProfile.Rows.Add(singleRow);
//所用者血型
singleRow = dtProfile.NewRow();
singleRow["Profile属性名称"] = "职业";
singleRow["Profile属性值"] = userProfile.职业;
dtProfile.Rows.Add(singleRow);
return dtProfile; //返回DataTable
}
//设置GridView外观样式
private void setGridViewStyle(GridView myGridView)
{
//设置GridView 外观属性
myGridView.Font.Size = 10;
myGridView.HeaderStyle.BackColor = Color.Tan;
myGridView.RowStyle.BackColor = Color.LightGoldenrodYellow;
myGridView.AlternatingRowStyle.BackColor = Color.PaleGoldenrod;
myGridView.HeaderStyle.ForeColor = Color.Black;
myGridView.PagerStyle.BackColor = Color.Goldenrod;
myGridView.Width=300;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -