我在asp.net中有页面,在此页面中有复选框。 我应该选中许多复选框然后按钮点击它应该转到相关列表并从下面的类中选择选中的项目。 所以我需要的是在运行时构建add select子句。
这个模型:
public class UserInfo
{
public int UserID { get; set; }
public string UserNameLogin { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public bool IsActive { get; set; }
public bool IsDeleted { get; set; }
public DateTime CreatedOn { get; set; }
public DateTime? ModifiedOn { get; set; }
}
这是清单:
static List<Models.UserInfo> _List_UserInfo = new List<Models.UserInfo>();
public void LoadUserInfo()
{
_List_UserInfo = Controllers.UserInfoController.GetUserInfo(Utility.GetDatabaseConnection());
}
然后从列表中选择项目应该是这样的:
_List_UserInfo =_List_UserInfo .select(x=>x.UserNameLogin );
但我需要在运行时选择多个项目。
答案 0 :(得分:0)
只需选择所有数据即可。除非其中一列是文件,否则获取完整的用户信息没有问题。
答案 1 :(得分:0)
我认为这就是你要找的东西。
using System;
using System.Collections.Generic;
using System.Linq;
namespace SampleConsoleApplication
{
public class Program
{
public class UserInfo
{
public int UserID { get; set; }
public string UserNameLogin { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public bool IsActive { get; set; }
public bool IsDeleted { get; set; }
public DateTime CreatedOn { get; set; }
public DateTime? ModifiedOn { get; set; }
}
public class UserInfoSubset
{
public int UserID { get; set; }
public string FullName { get; set; }
public string Email { get; set; }
}
public static void Main(string[] args)
{
// Assuming you loaded all information you needed from database.
var myList = new List<UserInfo>();
// Anonymous selection.
var subset1 = myList.Select(x => new
{
x.UserID,
FullName = string.Format("{0} {1}", x.FirstName, x.LastName)
}).ToList();
// Strong type selection.
var subset2 = myList.Select(x => new UserInfoSubset
{
UserID = x.UserID,
FullName = string.Format("{0} {1}", x.FirstName, x.LastName),
Email = x.Email
}).ToList();
}
}
}