0

在根据 RadListBox 中的选定值过滤 ObjectDataSource 之后,我试图以声明方式绑定到 DropDownList。更糟糕的是,我必须以声明方式在控件之间进行绑定。

由于我无法将 SelectParameters 绑定到我的 ListBox.SelectedItems 属性,因此我尝试从 RadListBox 继承并提供一个属性以将 IList 转换为对象。然后在我的服务中接受对象作为参数。但是,由于某种原因,该属性被无限调用。

标记:

<cust:CustomListBox ID="listTypes" 
                    AutoPostBack="true"
                    EnableLoadOnDemand="true"
                    DataTextField="Text" 
                    DataValueField="Value" 
                    DataSourceID="listTypesDataSource"
                    EnableEmbeddedSkins="false"
                    SelectionMode="Multiple"
                    runat="server" />

<cust:RadComboBox ID="aggregatedCompetitors1" 
                    AutoPostBack="true" 
                    DataSourceID="aggregatedCompetitors1DataSource" 
                    DataTextField="Text" 
                    DataValueField="Value" 
                    runat="server" />

<cust:ObjectDataSource ID="listTypesDataSource"
                      TypeName="TestServices.TestService"
                      SelectMethod="GetProductTypes"
                      runat="server" />

<cust:ObjectDataSource ID="aggregatedCompetitors1DataSource"
                      TypeName="TestServices.TestService"
                      SelectMethod="GetCompetitors1"
                      runat="server">
    <SelectParameters>
        <asp:ControlParameter Name="productTypes" 
                              ControlID="listTypes"
                              Type="Object"
                              PropertyName="SelectedValuesAsObject" />
    </SelectParameters>
</cust:ObjectDataSource>

代码:

public class CustomListBox : RadListBox
{
    public object SelectedValuesAsObject
    {
        get
        {
            return (object)this.SelectedItems;
        }
    }
}

我的测试服务类。

public class TestService
{
    public List<ListItem> GetProductTypes()
    {
        return ProductTypes();
    }

    public List<ListItem> GetCompetitors1(object productTypes)
    {
        IList<RadListBoxItem> selectedItems = (IList<RadListBoxItem>)productTypes;
        List<ListItem> aggregatedValues = new List<ListItem>();

        foreach(var selectedValue in selectedItems)
        {
            aggregatedValues.AddRange(Compeitors().Where(c => c.CompType == selectedValue.Value)
                .Where(c => c.Brand.In("Ford", "HP")));
        }

        return aggregatedValues;
    }

    private List<ListItem> ProductTypes()
    {
        return new List<ListItem>()
        {
            new ListItem("computers", "Computers"),
            new ListItem("cars", "Cars")
        };
    }

    private List<ListItem> Compeitors()
    {
        return new List<ListItem>()
        {
            new ListItem("Ford Tauris", "cars", "Ford"),
            new ListItem("Ford Escort", "cars", "Ford"),
            new ListItem("Ford Ranger", "cars", "Ford"),
            new ListItem("HP 2000z Series", "computers", "HP"),
            new ListItem("HP Pavillion g6t", "computers", "HP"),
            new ListItem("HP Pavillion g6z", "computers", "HP"),
            new ListItem("Chevy Impala", "cars", "Chevy"),
            new ListItem("Chevy Malibu", "cars", "Chevy"),
            new ListItem("Chevy Silverado", "cars", "Chevy"),
            new ListItem("Dell Precision T3500", "computers", "Dell"),
            new ListItem("Dell Precision T2500", "computers", "Dell"),
            new ListItem("Dell Latitude 2120", "computers", "Dell")
        };
    }
}

堆栈跟踪: 堆栈跟踪

4

0 回答 0