简体   繁体   English

C#在RadComboboxItem上使用.Contains搜索字符串

[英]C# Using .Contains on a RadComboboxItem searching for a string

Currently I am trying to create some cascading combo boxes. 目前,我正在尝试创建一些级联的组合框。 The program has 4 RadComboBoxes (telerik control). 该程序有4个RadComboBoxes(telerik控件)。 I place the default data into dropdowns and all is good. 我将默认数据放入下拉列表,一切都很好。 I can multi-select from these boxes. 我可以从这些框中进行多重选择。 When I select values from box 1 it should filter the choices in box 2. 当我从方框1中选择值时,它应该过滤方框2中的选择。

protected void rcbProgram_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {            
        rcbPartGroup.DataSource = db.tblPartStyles.Where(c=>rcbProgram.CheckedItems.Contains(c.Program)).Select(c => c.PartGroup);
        rcbPartGroup.DataBind();

    }

I want rcbPartGroup's datasource to be the PartGroup field of tblPartStyles where the Program field is in rcbProgram's checked list. 我希望rcbPartGroup的数据源是tblPartStyles的PartGroup字段,其中Program字段位于rcbProgram的已选中列表中。 This would work fine, but rcbProgram.CheckedList is a List and will not compare with a string (The program field value). 这可以正常工作,但是rcbProgram.CheckedList是一个List,并且不会与字符串(程序字段值)进行比较。 I am still having a difficult time wrapping my head around how this would work if both are strings, but now I have 2 different types that I cannot manage to convert. 我仍然很难理解如果两个都是字符串,这将如何工作,但是现在我有两种无法转换的不同类型。 Anyone have anything they know that I can do to make this work? 有人知道我可以做些什么吗?

I was a bit confused by the lambda statement at first. 起初我对lambda语句感到有些困惑。 I did a simple fix. 我做了一个简单的修复。 I created a list of strings and ran through a foreach to add the values in the CheckedItems list. 我创建了一个字符串列表,并运行了一个foreach以将值添加到CheckedItems列表中。 I then used the string list to perform the lambda filter. 然后,我使用字符串列表执行了lambda过滤器。

 protected void rcbProgram_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        **List<String> _selectedItems = new List<String>();
        foreach (RadComboBoxItem i in rcbProgram.CheckedItems)
        {
            _selectedItems.Add(i.Value);
        }**


        rcbPartGroup.DataSource = db.tblPartStyles.Where(c=>_selectedItems.Contains(c.Program)).Select(c => c.PartGroup).Distinct();
        rcbPartGroup.DataBind();

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM