C# 列表上的条件筛选器

C# 列表上的条件筛选器,c#,linq,C#,Linq,在对每个复选框使用Where语句进行过滤之后,我绑定到网格上——但记录的数量始终相同——几乎就像没有应用过滤器一样。为什么dbRecords没有被Where语句调整?Where()返回一个新的筛选列表,它不会修改原始列表,因此您需要像这样存储筛选列表: var dbRecords = (from c ...... query removed).Where(c => c.BNumber.Contains(bnum)).ToList(); // At this point dbRecords

在对每个复选框使用Where语句进行过滤之后,我绑定到网格上——但记录的数量始终相同——几乎就像没有应用过滤器一样。为什么dbRecords没有被Where语句调整?

Where()
返回一个新的筛选列表,它不会修改原始列表,因此您需要像这样存储筛选列表:

var dbRecords = (from c ...... query removed).Where(c => c.BNumber.Contains(bnum)).ToList();

// At this point dbRecords contains 596 records

int chkCount = 0;

// I have a series of checkboxes for filtering of the query

foreach (ListItem c in chklColumns.Items)
{
    if (c.Selected == true)
    {
        chkCount++;
    }
    if (chkCount > 0)
    {
        foreach (ListItem x in chklColumns.Items)
        {
            var gridKey = "Grp" + x.Value;

            if (x.Selected)
            {
               if (gridKey == "GrpSOS")
               {
                   dbRecords.Where(p => p.SOSEnabledYN == true);
               }
               if (gridKey == "GrpMOB")
               {
                   dbRecords.Where(p => p.ZMobileEnabledYN == true);

                   // If this filter were applied then my resultset would be 276 records
                   // I step through and hit this code but it does not seem to be affecting the dbRecords list
               }
               if (gridKey == "GrpPHO")
               {
                   dbRecords.Where(p => p.PhoneMonitorEnabledYN == true);
               }
           }
       }
   }

WebDataGrid1.DataSource = dbRecords;
WebDataGrid1.DataBind();
例子:
List myUsers=New List();
//用一些用户对象填充myUsers列表
列出activeUsers=myUsers.Where(u=>u.Active==True);
//activeUsers列表将只包含从所有用户列表中筛选出的活动用户
其中()
返回一个新的筛选列表,它不会修改原始列表,因此您需要按如下方式存储筛选列表:

var dbRecords = (from c ...... query removed).Where(c => c.BNumber.Contains(bnum)).ToList();

// At this point dbRecords contains 596 records

int chkCount = 0;

// I have a series of checkboxes for filtering of the query

foreach (ListItem c in chklColumns.Items)
{
    if (c.Selected == true)
    {
        chkCount++;
    }
    if (chkCount > 0)
    {
        foreach (ListItem x in chklColumns.Items)
        {
            var gridKey = "Grp" + x.Value;

            if (x.Selected)
            {
               if (gridKey == "GrpSOS")
               {
                   dbRecords.Where(p => p.SOSEnabledYN == true);
               }
               if (gridKey == "GrpMOB")
               {
                   dbRecords.Where(p => p.ZMobileEnabledYN == true);

                   // If this filter were applied then my resultset would be 276 records
                   // I step through and hit this code but it does not seem to be affecting the dbRecords list
               }
               if (gridKey == "GrpPHO")
               {
                   dbRecords.Where(p => p.PhoneMonitorEnabledYN == true);
               }
           }
       }
   }

WebDataGrid1.DataSource = dbRecords;
WebDataGrid1.DataBind();
例子:
List myUsers=New List();
//用一些用户对象填充myUsers列表
列出activeUsers=myUsers.Where(u=>u.Active==True);
//activeUsers列表将只包含从所有用户列表中筛选出的活动用户
其中()
返回一个新的筛选列表,它不会修改原始列表,因此您需要按如下方式存储筛选列表:

var dbRecords = (from c ...... query removed).Where(c => c.BNumber.Contains(bnum)).ToList();

// At this point dbRecords contains 596 records

int chkCount = 0;

// I have a series of checkboxes for filtering of the query

foreach (ListItem c in chklColumns.Items)
{
    if (c.Selected == true)
    {
        chkCount++;
    }
    if (chkCount > 0)
    {
        foreach (ListItem x in chklColumns.Items)
        {
            var gridKey = "Grp" + x.Value;

            if (x.Selected)
            {
               if (gridKey == "GrpSOS")
               {
                   dbRecords.Where(p => p.SOSEnabledYN == true);
               }
               if (gridKey == "GrpMOB")
               {
                   dbRecords.Where(p => p.ZMobileEnabledYN == true);

                   // If this filter were applied then my resultset would be 276 records
                   // I step through and hit this code but it does not seem to be affecting the dbRecords list
               }
               if (gridKey == "GrpPHO")
               {
                   dbRecords.Where(p => p.PhoneMonitorEnabledYN == true);
               }
           }
       }
   }

WebDataGrid1.DataSource = dbRecords;
WebDataGrid1.DataBind();
例子:
List myUsers=New List();
//用一些用户对象填充myUsers列表
列出activeUsers=myUsers.Where(u=>u.Active==True);
//activeUsers列表将只包含从所有用户列表中筛选出的活动用户
其中()
返回一个新的筛选列表,它不会修改原始列表,因此您需要按如下方式存储筛选列表:

var dbRecords = (from c ...... query removed).Where(c => c.BNumber.Contains(bnum)).ToList();

// At this point dbRecords contains 596 records

int chkCount = 0;

// I have a series of checkboxes for filtering of the query

foreach (ListItem c in chklColumns.Items)
{
    if (c.Selected == true)
    {
        chkCount++;
    }
    if (chkCount > 0)
    {
        foreach (ListItem x in chklColumns.Items)
        {
            var gridKey = "Grp" + x.Value;

            if (x.Selected)
            {
               if (gridKey == "GrpSOS")
               {
                   dbRecords.Where(p => p.SOSEnabledYN == true);
               }
               if (gridKey == "GrpMOB")
               {
                   dbRecords.Where(p => p.ZMobileEnabledYN == true);

                   // If this filter were applied then my resultset would be 276 records
                   // I step through and hit this code but it does not seem to be affecting the dbRecords list
               }
               if (gridKey == "GrpPHO")
               {
                   dbRecords.Where(p => p.PhoneMonitorEnabledYN == true);
               }
           }
       }
   }

WebDataGrid1.DataSource = dbRecords;
WebDataGrid1.DataBind();
例子:
List myUsers=New List();
//用一些用户对象填充myUsers列表
列出activeUsers=myUsers.Where(u=>u.Active==True);
//activeUsers列表将只包含从所有用户列表中筛选出的活动用户

花点时间阅读帮助中心中的。堆栈溢出上的格式设置与其他站点不同。你的帖子越好看,用户就越容易帮助你。花点时间阅读帮助中心中的。堆栈溢出上的格式设置与其他站点不同。你的帖子越好看,用户就越容易帮助你。花点时间阅读帮助中心中的。堆栈溢出上的格式设置与其他站点不同。你的帖子越好看,用户就越容易帮助你。花点时间阅读帮助中心中的。堆栈溢出上的格式设置与其他站点不同。你的帖子越好看,用户就越容易帮助你。谢谢-我曾经试过这样做,但我不得不在我最初的查询中列出。一旦我删除了,我就可以重新分配数据库记录了。谢谢-我已经试着这么做了,但是我必须在我的原始查询中列出。一旦我删除了,我就可以重新分配数据库记录了。谢谢-我已经试着这么做了,但是我必须在我的原始查询中列出。一旦我删除了,我就可以重新分配数据库记录了。谢谢-我已经试着这么做了,但是我必须在我的原始查询中列出。一旦我删除了,我就能够重新分配dbRecords。