简体   繁体   English

如何在DNN中获取特定的userinfo

[英]How to get the particular userinfo in DNN

Hi I'm using C# in developing my module in DNN and I have retrieved the users using this : 嗨,我在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;
}

And I bind it here: 我在这里绑定它:

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();
}

And it is working fine. 而且工作正常。 It shows all the information regarding the user of the portal such as: 它显示有关门户网站用户的所有信息,例如:

Email 
Firstname 
Lastname 
portalID

etc... 等等...

And that I dont want. 而我不想。 Because I only need the UserID, Username and the DisplayName of the user. 因为我只需要用户ID,用户名和用户的DisplayName。 How can I do this? 我怎样才能做到这一点? Any suggestions? 有什么建议么?

Add a new simple class to your code that has only the fields you need. 将新的简单类添加到仅包含所需字段的代码中。

public class UserBindings
{
    public int UserID { get; set; }
    public string Username { get; set; }
    public string DisplayName { get; set; }
}

Then make a slight change to your binding method: 然后对您的绑定方法进行一些更改:

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();
}

I had to cast the Arraylist and use Linq to map the UserInfo to the UserBinding object. 我必须转换Arraylist并使用Linq将UserInfo映射到UserBinding对象。 Now this method will return a list of UserBinding which is a much smaller collection than the previous ArrayList of UserInfo objects. 现在,此方法将返回UserBinding列表,该列表比以前的UserInfo对象的ArrayList小得多。

You could also define the columns/properties in the GridView that you want to display if you simply want to limit what is being displayed. 如果只想限制显示的内容,也可以在GridView中定义要显示的列/属性。 It sounds like you are letting it provide all the columns for all the properties. 听起来您正在让它提供所有属性的所有列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM