开发者

problem with a LINQ statement using RadComboBox and RadListBox

开发者 https://www.devze.com 2023-02-08 17:53 出处:网络
i have this rad combo box (aka dropdownlist) with items \"count\" \"sum\" \"max\" \"min\" which i append to a RadListBox control item so it comes out like this \"Count(column1)\"

i have this rad combo box (aka dropdownlist) with items "count" "sum" "max" "min" which i append to a RadListBox control item so it comes out like this "Count(column1)" on rcListBoxColumns2. then i write my code like this and get no result:

var ddlFunc = from cp in ddlFunctions.Items.ToList() select cp;
var rcLBC = from p in rcListBoxColumns2.Items.ToList() select开发者_JS百科 p;


havingFilters.DataSource = (from p in rcLBC.ToList()
                                        from x in ddlFunc.ToList()
                                        where p.Value.Contains(x.Value)
                                        select new { Value = p.Value, Text = p.Text }).Distinct().ToList();

I can use the debugger and look at ddlFunc and also rcLBC, and I notice rcLBC have values that should "contain" the dropdownlist values, but my result is ALL items being selected. Can't figure out why the contains statement didn't filter it. Any ideas anyone?


I am assuming you are trying to filter on Value, so try this:

havingFilters.DataSource = (
    from p in rcLBC
    where (
        from x in ddlFunc
        where p.Value.Contains(x.Value)
        select x).Any()
    select new
    {
        Value = p.Value,
        Text = p.Text
    });


I just solved it, apparently my ddlFunctions had a value of "" <- empty string. This caused the string.contains function to return true for any string.

0

精彩评论

暂无评论...
验证码 换一张
取 消