Generic Filter

Posts   
 
    
Russel
User
Posts: 2
Joined: 22-Jun-2008
# Posted on: 22-Jun-2008 18:59:42   

Hi,

For my customer I'm appointed to see if LLBLGen Pro can replace their current framework. So far it looks promising.

Currently I'm looking if I can replace their current generic filtering usercontrol. I have some problems with it, I hope you can help me.

What I want: Create a usercontrol where data can be filtered. The usercontrol consist of some fields. For this example I will cut it down to 2: - a dropdown list containing the properties of the object. - a textfield where a value can be entered and ofcourse the button

I want to create 2 properties on the usercontrol. - One of the type CommonEntityBase where the entity type can be set to: - and a property containing the result list

For test purposes I created a grid to see the result.

So far I have the following:


    private CommonEntityBase _zoekObject = null;
    public CommonEntityBase ZoekObject
    {
        get { return _zoekObject; }
        set { _zoekObject = value; }
    }   


    protected void Page_Load(object sender, EventArgs e)
    {
        //For test purposes just set the ZoekObject  to an entity
        this.ZoekObject = new FpsReden();

        if (!Page.IsPostBack)
        {       

            // Build the dropdown list
            foreach (EntityField entiteit in _zoekObject.Fields)
            {
                ddlProperties.Items.Add(new ListItem(entiteit.Name, entiteit.Name));
            }
            //Add empty value to dropdown
            ddlProperties.Items.Insert(0, new ListItem());
        }
    }

    //Temporarily use a dirty method to retrieve the Entity field based upon string name
    private EntityField getField(string name)
    {
        foreach (EntityField entiteit in _zoekObject.Fields)
        {
            if (entiteit.Name == name)
                return entiteit;
        }
        return null;
    }

    //Ok let's try to filter the data
    protected void btnFilter_Click(object sender, EventArgs e)
    {
        // Create filter
        IPredicateExpression filter = new PredicateExpression();

        // Add a filter expression to the filter -> TODO add multiple filter statements
        FieldLikePredicate predicate = new FieldLikePredicate(this.getField(ddlProperties.SelectedValue), "%" + txtValue.Text + "%");
        filter.Add(predicate);
        
        
        // How to fill a collection without using FpsRedenCollection??
        FpsRedenCollection reden = new FpsRedenCollection();
        reden.GetMulti(filter);

        RadGrid1.DataSource = reden;
        RadGrid1.DataBind();
    }

As you can see I have to use FpsRedenCollection to be able to execute the GetMulti(). IS there a way to execute GetMulti without using a hardcoded collection?

Looking forward to your reply.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-Jun-2008 20:22:53   

Hi Russel, this similar thread could be helpful: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=6304

David Elizondo | LLBLGen Support Team
Russel
User
Posts: 2
Joined: 22-Jun-2008
# Posted on: 22-Jun-2008 21:58:39   

Hi Daelmo,

Thanks for your reply. I hoped reflection wasn't necessary, but I will fix this problem by using reflection.

[edit] Ooopss I responded too fast.

The following code did the trick:


        IEntityCollection coll = _zoekObject.GetEntityFactory().CreateEntityCollection();
        coll.GetMulti(filter);

[/edit]