Binding EntityCollection to GridView - filter not applying

Posts   
 
    
daz_oldham avatar
daz_oldham
User
Posts: 62
Joined: 20-Jul-2007
# Posted on: 20-Sep-2007 09:51:57   

Hello

I'm trying to bind an entity collection to the gridview - it works, but my filter is not having any effect. I've put my code below - where am I going wrong?

Note: I have tried taking the IF statements out so the filter is fully built up... but it had no effect.

Many thanks

Darren

P.S. I am on the latest version, self servicing with SQL Server

        PredicateExpression filter = new PredicateExpression();
        filter.Add(ProductFields.CatalogueId == Int32.Parse(ConfigurationManager.AppSettings["CatalogueMainID"].ToString()));
        
        if(txtProductId.Text.Length > 0)
            filter.AddWithAnd(ProductFields.ProductId == Int32.Parse(txtProductId.Text));

        if (txtPLU.Text.Length > 0)
            filter.AddWithAnd(ProductFields.Plu == txtPLU.Text);

        if (lstCategory.SelectedIndex > 0)
            filter.AddWithAnd(ProductFields.CategoryId == Int32.Parse(lstCategory.SelectedValue));
        

        SortExpression sort = new SortExpression();
        SortClause clause = new SortClause(ProductFields.Name, SortOperator.Ascending);
        sort.Add(clause);

        ProductCollection products = new ProductCollection();
        products.GetMulti(filter, 99999, sort);


        LLBLGenProDataSource dsProducts = new LLBLGenProDataSource();
        dsProducts.CacheLocation = DataSourceCacheLocation.Session;
        dsProducts.DataContainerType = DataSourceDataContainerType.EntityCollection;
        dsProducts.EnablePaging = true;
        dsProducts.EntityCollection = products;
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Sep-2007 11:26:20   

Why don't you declare the LLBLGenProDataSource in the aspx file, rather than in code? So you can set it properties at design time. eg.

        <llblgenpro:LLBLGenProDataSource ID="CustomersDS" runat="server" DataContainerType="EntityCollection"           EntityCollectionTypeName="SD.LLBLGen.Pro.Examples.CollectionClasses.CustomerCollection, SD.LLBLGen.Pro.Examples" EnablePaging="True" AllowDuplicates="False">
        </llblgenpro:LLBLGenProDataSource>

Anyway you need to set the EntityCollectionTypeName of the LLBLGenProDataSource.

Also the LLBLGenProDataSource.LivePersistence is set to true by default, which let the LLBLGenProDataSource fetch the collection on its own. So the collection fetched by your GetMulti() call isn't really what the LLBLGenProDataSource returns.

If you want to perform the fetch yourself, then set LLBLGenProDataSource.LivePersistence to false and handle the PerformSelect event. You will also need to handle other events.

Please refer to the docs: "Using the generated code -> SelfServicing -> Databinding at designtime and runtime -> Databinding with ASP.NET 2.0"