文本框(RadTextBox)应该通过使用ObjectDataSource的FilterExpression来过滤ListView(RadListView) . ObjectDataSource的基础数据源是WCF服务 .

它不起作用 . 在我的所有试验和错误中,我所能得到的只是整个数据集绑定到ListView或根本没有记录 . 通过从文本框中的输入过滤它,我无法获得选择的几条记录 .

Here是一个帮助者视频(此时有点绝望......)

提前致谢!

RadListView:

<telerik:RadListView ID="RadListView1" runat="server"
                                    DataSourceID="ObjectDataSource1" AllowPaging="True"
                                    ItemPlaceholderID="ListingsContainer" Width="940px" SkinID="Bootstrap">

ObjectDataSource控件:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" EnablePaging="true" TypeName="manageListingsController" SelectMethod="GetProducts" StartRowIndexParameterName="startRowIndex"
                    SelectCountMethod="GetProductsCount" FilterExpression="ItemID = '{0}%'" InsertMethod="InsertProduct" DeleteMethod="DeleteProduct" UpdateMethod="UpdateProduct" OldValuesParameterFormatString="Original_{0}" SortParameterName="sortExpression">
                    <FilterParameters>
                        <asp:ControlParameter Name="@ItemID" ControlID="txtItemID" ConvertEmptyStringToNull="false" Type="String" />
                    </FilterParameters>
                    <InsertParameters>
                        <asp:Parameter Name="ItemID" Type="String" />
                        <asp:Parameter Name="SiteID" Type="Int32" />
                        <asp:Parameter Name="Price" Type="Decimal" />
                        <asp:Parameter Name="Quantity" Type="Int32" />
                        <asp:Parameter Name="ProductID" Type="String" />
                        <asp:Parameter Name="Condition" Type="String" />
                        <asp:Parameter Name="ToAP" Type="Boolean" />
                    </InsertParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="ItemID" Type="String" />
                        <asp:Parameter Name="SiteID" Type="Int32" />
                        <asp:Parameter Name="Price" Type="Decimal" />
                        <asp:Parameter Name="Quantity" Type="Int32" />
                        <asp:Parameter Name="ProductID" Type="String" />
                        <asp:Parameter Name="Condition" Type="String" />
                        <asp:Parameter Name="ToAP" Type="Boolean" />
                        <asp:Parameter Name="Original_ID" Type="Int32"></asp:Parameter>
                    </UpdateParameters>
                    <DeleteParameters>
                        <asp:Parameter Name="ItemID" Type="String" />
                        <asp:Parameter Name="SiteID" Type="Int32" />
                        <asp:Parameter Name="Original_ID" Type="Int32"></asp:Parameter>
                    </DeleteParameters>
                </asp:ObjectDataSource>

GetProducts方法:

public DataTable GetProducts(int startRowIndex,
    int maximumRows,
    string sortExpression)
{
    ProductsAPI.ProductsClient pCl = new ProductsAPI.ProductsClient();
    DataTable n = new DataTable();

    try
    {
        rowCount = temp.Count;
        try
        {
            n = Help.ToDataTable(temp.ProductData.ToList());
        }
        catch (Exception ex)
        { 
            Console.WriteLine(ex.Message); 
        }
    }
    catch (Exception ex)
    {
        Exceptions.ProcessModuleLoadException(null, ex);
    }

    return n;
}

WCF GetProducts OperationContract:

[OperationContract]
    public ResultData GetProducts(int startRowIndex, int maximumRows, string sortExpression, string filterExpression)
    {
        DAL.Products.Products p = DAL.Products.Products.Instance();

        return p.GetDataAndCount(startRowIndex, maximumRows, sortExpression, filterExpression);
    }

WCF GetDataAndCount方法:

public ResultData GetDataAndCount(int startRowIndex, int maximumRows, string sortExpression, string filterExpression)
    {
        //http://demos.telerik.com/aspnet-ajax/grid/examples/data-binding/client-side/declarative/defaultcs.aspx
        //http://demos.telerik.com/aspnet-ajax/listview/examples/client/webservicedatabinding/defaultcs.aspx

        GridLinqBindingData<v_mp_GenListings_Data> data = RadGrid.GetBindingData(
            (new Entities()).v_mp_GenListings_Data.OrderByDescending(p => p.ProductID),
            startRowIndex, maximumRows, sortExpression, filterExpression);

        ResultData result = new ResultData();

        result.ProductData = data.Data.OfType<v_mp_GenListings_Data>().Select(p => new Product()
        {
            ItemID = p.ItemID,
            SKU = p.SKU,
            ID = p.ID,
            SiteID = p.SiteID,
            MarketPlaceType = p.MarketplaceType,
            SiteName = p.SiteName,
            //AccOverride = p.AccOverride,
            //ToAP = p.ToAP,
            //CeilingPriceFixed = p.CeilingPriceFixed,
            //Min = p.Min,
            NightModeID = p.NightModeID,
            NightModeCode = p.NightModeCode,
            ToMAP = p.ToMAP,
            ConditionID = p.ConditionID,
            MerchantID = p.MerchantID,
            ProductID = p.ProductID,
            Quantity = p.Quantity,
            Price = p.Price,
            URL = p.URL

        }).ToList();

        result.Count = data.Count;
        return result;
    }