筛选列表,包含2个下拉列表

时间:2013-03-28 16:13:59

标签: c# linq listview filtering

我有2个下拉列表和列表视图:

<option value="Please choose...">Please choose...</option>
<option value="Permanent">Permanent</option>
<option value="Part Time">Part Time</option>
<option value="Volunteer">Volunteer</option>
<option value="Temporary">Temporary</option>

<option value="Please choose...">Please choose...</option>
<option value="South West">South West</option>
<option value="South East">South East</option>
<option value="London">London</option>
<option value="East of England">East of England</option>
<option value="West Midlands">West Midlands</option>
<option value="East Midlands">East Midlands</option>
<option value="North West">North West</option>
<option value="North East">North East</option>
<option value="Yorkshire &amp; Humberside">Yorkshire &amp; Humberside</option>
<option value="UK">UK</option>
<option value="Midlands">Midlands</option>

我想使用这两个下拉值过滤项目列表。如果选择了索引0(请选择),则应返回该属性的全部内容。

这是我的代码,但是当您从第二个下拉列表中选择某些内容时,结果不正确。

protected void LoadCareerList(string jobType = "", string jobLocation = "")
    {
        var currentNode = Node.GetCurrent();
        var nodeList = new List<Node>();
        lblVacancyCount.Text = "Current vacancies: 0";

        foreach (Node node in currentNode.Children)
        {
            nodeList.Add(node);
        }

        if (nodeList.Count > 0)
        {
            List<Node> filteredList = nodeList.Where(
                    x => ((ddlFilterType.SelectedIndex == 0 || x.GetProperty("jobType").Value.Replace(" ", "").ToLower().Contains(jobType.Replace(" ", "").ToLower()))) && ((ddlFilterLocation.SelectedIndex == 0 || x.GetProperty("jobLocation").Value.Replace(" ", "").ToLower().Contains(jobLocation.Replace(" ", "").ToLower())))).OrderByDescending(x => x.GetProperty("jobDatePosted").Value).ToList();

            lvCareers.DataSource = filteredList;
            lvCareers.DataBind();
            lblVacancyCount.Text = "Current vacancies: " + filteredList.Count.ToString(CultureInfo.InvariantCulture);

        }
    }

到目前为止,我在系统中有3条记录: 职业1 = Midlands&amp;常驻 职业2 =伦敦&amp;常驻 职业3 = Midlands&amp;临时 当我选择Permanent I获得2条记录时,在第二条过滤器中选择London将返回0条记录。

0 个答案:

没有答案