我需要根据复选框列表中选择特定的列 [英] I need to select particular column based on check box list

查看:127
本文介绍了我需要根据复选框列表中选择特定的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在该用户的复选框列表可以选中或取消选中该复选框。

I have a check box list in that user can check or uncheck the check box.

根据我用来存储逗号该值分隔复选框。现在的问题是基于选中复选框,我需要一个人得到特定列。在选择**

Based on the selected check box I used to store that value by comma separated. Now the problem is based on selected check box I need to get that particular column alone. in "select"**

db.Tasks.OrderBy(t => t.CreatedDate).ToList()
  .Select(t => new {
       Id = t.Id, 
       PriorityId = t.ProjectId, 
       Priority = t.Priority, 
       StatusId = t.StatusId, 
       Status = t.Status,
       EstimatedTime = t.EstimatedTime, 
       ActualTime = t.ActualTime, 
       Subject = t.Subject, 
       FileName = t.FileName,
       AssignedTo = t.AssignedTo, 
       Project = t.Project 
   }).ToList();

如果我选择复选框列表ActualTime,主题,它应该是像

if i select in check box list ActualTime, Subject, it should be like

db.Tasks.OrderBy(t => t.CreatedDate).ToList()
  .Select(t => new {
       Id = t.Id,       
       ActualTime = t.ActualTime, 
       Subject = t.Subject
   }).ToList();

如果我在复选框列表中选择主题,文件名,AssignedTo,应该像

if i select in check box list Subject, FileName, AssignedTo, it should be like

db.Tasks.OrderBy(t => t.CreatedDate).ToList()
  .Select(t => new {
           Id = t.Id,  
           Subject = t.Subject, 
           FileName = t.FileName,
           AssignedTo = t.AssignedTo
       }).ToList();

选择将根据选中的复选框名单是动态的。

the select will be dynamic based on selected check box list.

推荐答案

添加DynamicLibrary.cs到项目中。
 您可以从链接得到它。它包含动态链接源的zip文件。这不是一个DLL。
 原本张贴在ScottGu的博客<一href=\"http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx\"相对=nofollow>此处。
 参考看到这个堆栈溢出<一个href=\"http://stackoverflow.com/questions/3991108/where-can-i-find-the-system-linq-dynamic-dll\">link

add DynamicLibrary.cs to your project. You can get it from this link . It's a zip file that contains the dynamic link source. It's not a dll. Originally posted on ScottGu's blog here. for reference see this stack overflow link .

    using System.Linq.Dynamic;

    public class DynamicColumns : BaseEntity
    {
        public string User { get; set; }
        public string TaskId { get; set; }
        public string Project { get; set; }
        public string Priority { get; set; }
        public string TaskType { get; set; }
        public string Version { get; set; }
        public string Module { get; set; }
        public string Subject { get; set; }
        public string Details { get; set; }
        public string FileName { get; set; }
        public string Status { get; set; }          
        public string AssignedBy { get; set; }
        public string AssignedTo { get; set; }
        public int ActualTime { get; set; }
        public int LogWork { get; set; }
        public DateTime CreatedDate { get; set; }
        public DateTime AssignedDate { get; set; }
        public DateTime ResolveDate { get; set; }
        public int EstimatedTime { get; set; }
    }

    public enum EnumTasks
    {

        User = 1,
        Project = 2,
        Priority = 3,
        TaskType = 4,
        Version = 5,
        Module = 6,
        Subject = 7,
        Details = 8,          
        Status = 9,            
        Assigned_By = 10,
        Assigned_To = 11,
        Created_Date = 12,
        Assigned_Date = 13,
        Resolve_Date = 14,
        Estimated_Time = 15,
        Actual_Time = 16,
        LogWork = 17
    }

    public IQueryable DynamicSelectionColumns()
    {
        using (var db = new TrackerDataContext())
        {
            string fieldIds = "," + "4,5,3,2,6,17,11,12" + ",";

            var taskColum = Enum.GetValues(typeof(EnumTasks)).Cast<EnumTasks>().Where(e => fieldIds.Contains("," + ((int)e).ToString() + ",")).Select(e => e.ToString().Replace("_", ""));

            string select = "new (  TaskId, " + (taskColum.Count() > 0 ? string.Join(", ", taskColum) + ", " : "") + "Id )";

            return db.Task.ToList().Select(t => new DynamicColumns() { Id = t.Id, TaskId = Project != null ? Project.Alias + "-" + t.Id : t.Id.ToString(), ActualTime = t.ActualTime, AssignedBy = t.AssignedBy.ToString(), AssignedDate = t.AssignedDate, AssignedTo = t.AssignedTo.ToString(), CreatedDate = t.CreatedDate, Details = t.Details, EstimatedTime = t.EstimatedTime, FileName = t.FileName, LogWork = t.LogWork, Module = t.Module != null ? t.Module.Name : "", Priority = t.Priority != null ? t.Priority.Name : "", Project = t.Project != null ? t.Project.Name : "", ResolveDate = t.ResolveDate, Status = t.Status != null ? t.Status.Name : "", Subject = t.Subject, TaskType = t.TaskType != null ? t.TaskType.Type : "", Version = t.Version != null ? t.Version.Name : "" }).ToList().AsQueryable().Select(select);
        }
    }

这篇关于我需要根据复选框列表中选择特定的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆