[英]How to get the particular userinfo in DNN
嗨,我在DNN中开发模块时使用的是C#,并使用以下方法检索了用户:
public ArrayList bindingListHere(string txtSearchUser){
string getUsers = txtSearchUser;
int totalrecords = 10;
Users= UserController.GetUsersByUserName(PortalId, getUsers + "%", 0, 10, ref totalrecords, true, IsSuperUser);
return Users;
}
我在这里绑定它:
protected void Search(object sender, EventArgs e){
//calling the method from the lib that will search user of the portal
DownloadCtrLib dctrl = new DownloadCtrLib ();
dctrl.bindingListHere (txtSearchUser.Text);
gvUser.DataSource = dctrl.bindingListHere (txtSearchUser.Text);
gvUser.DataBind();
}
而且工作正常。 它显示有关门户网站用户的所有信息,例如:
Email
Firstname
Lastname
portalID
等等...
而我不想。 因为我只需要用户ID,用户名和用户的DisplayName。 我怎样才能做到这一点? 有什么建议么?
将新的简单类添加到仅包含所需字段的代码中。
public class UserBindings
{
public int UserID { get; set; }
public string Username { get; set; }
public string DisplayName { get; set; }
}
然后对您的绑定方法进行一些更改:
public List<UserBindings> bindingListHere(string txtSearchUser)
{
string getUsers = txtSearchUser;
int totalrecords = 10;
ArrayList Users = UserController.GetUsersByUserName(PortalId, getUsers + "%", 0, 10, ref totalrecords, true, IsSuperUser);
return Users.Cast<UserInfo>().Select(u => new UserBindings { UserID = u.UserID, Username = u.Username, DisplayName = u.DisplayName }).ToList();
}
我必须转换Arraylist并使用Linq将UserInfo映射到UserBinding对象。 现在,此方法将返回UserBinding列表,该列表比以前的UserInfo对象的ArrayList小得多。
如果只想限制显示的内容,也可以在GridView中定义要显示的列/属性。 听起来您正在让它提供所有属性的所有列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.