Best method for filtering

Posts   
 
    
Posts: 12
Joined: 14-May-2006
# Posted on: 01-Jun-2006 00:58:19   

Hi

I have been trying to build a page that shows all records by default but can filter by a status field.

I am unsure where to place the code for filtering and the exact syntax to use. Can the filtering code be placed in the performselect event?

I have tried the following but am getting an obj ref error. confused

protected void OrdersDS_PerformSelect(object sender, PerformSelectEventArgs2 e)
{
        using (DataAccessAdapter da = new DataAccessAdapter())
        {
            if (DropDownList1.SelectedValue != "-1" && DropDownList1.SelectedValue != "")
            {
                e.Filter.PredicateExpression.Add((StockOrderFields.OrderStatusId == DropDownList1.SelectedValue));
                da.FetchEntityCollection(e.ContainedCollection, e.Filter, 0, e.Sorter, e.PrefetchPath);
            }
            else
            {
                da.FetchEntityCollection(e.ContainedCollection, e.Filter, 0, e.Sorter, e.PrefetchPath);
            }
        }
    }

Sorry if i'm being retarded but I'm trying to move to both lblgen v2 and asp.net v2 and it's all a bit much atm as my usual methods won't work! cry

Also is the llblgen code compatible with the microsoft reporting bundled with dotnet 2? If not is there any plan to support it, or do you have any recommendations?

Thanks

Richard

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 01-Jun-2006 08:08:07   

Would you please post the exact error text and the stack trace?

Thanks.

Posts: 12
Joined: 14-May-2006
# Posted on: 01-Jun-2006 08:54:43   
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 01-Jun-2006 09:24:54   

caveman_dick wrote:

Hi

I have been trying to build a page that shows all records by default but can filter by a status field.

I am unsure where to place the code for filtering and the exact syntax to use. Can the filtering code be placed in the performselect event?

As the value on which you want to filter is a value in a dropdownbox, you can do this at design time by specifying a SelectParameter for the OrdersDS.

Open your page in design view in vs.net, select OrdersDS and go to the property grid of vs.net, there you'll see SelectParameters. select it in the properties grid and you'll see a button [...]. Click it and a designer opens. There you can add a new select parameter which should retrieve its value from the dropdownbox DropDownList1. It results in this HTML which will be placed inside the LLBLGenProDataSource2 tags: <SelectParameters> <asp:ControlParameter ControlID="_countrySelector" Name="Country" PropertyName="SelectedValue" /> </SelectParameters>

(example) This is a big step forward from ASP.NET 1.x, but you have to learn from scratch how it works, so take your time simple_smile It might be good to read a tutorial or two about parameter binding in ASP.NET 2.0, as it's very powerful.

You can also rework your code if you like that more, your code crashes because you assume Filter has a value, but as you didn't set a filter, it crashes as it's null. So first add your filter to a RelationPredicateBucket, then simply use that relationpredicatebucket in teh FetchEntityCollection.

Also is the llblgen code compatible with the microsoft reporting bundled with dotnet 2? If not is there any plan to support it, or do you have any recommendations?

I'm not familiar with microsoft reporting, but if ms reporting is software written to be used by everyone, I don't see why llblgen pro code wouldn't work with ms reporting.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 01-Jun-2006 12:49:59   

Richard, I've created a video for you which illustrates what I meant:

http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=6410

(I had to try out and learn how to use DemoBuilder anyway wink )

Frans Bouma | Lead developer LLBLGen Pro
Posts: 12
Joined: 14-May-2006
# Posted on: 01-Jun-2006 22:07:53   

Thanks for the video, I had already tried that which is why i tried to do it manually. I tried again tonight and guess what it worked!!! smile

I also happened to notice the problem, i had put the select parameter on the wrong datasource!!! flushed proper doh moment!!! Frans, please tell me what punishment i deserve?!?!?

Thanks for help as always!

Richard

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 02-Jun-2006 12:52:02   

caveman_dick wrote:

Thanks for the video, I had already tried that which is why i tried to do it manually. I tried again tonight and guess what it worked!!! smile

heh smile

I also happened to notice the problem, i had put the select parameter on the wrong datasource!!! flushed proper doh moment!!! Frans, please tell me what punishment i deserve?!?!?

I'll spend some serious time on thinking about a punishment, Caveman wink

Frans Bouma | Lead developer LLBLGen Pro
drice avatar
drice
User
Posts: 2
Joined: 27-Jul-2006
# Posted on: 27-Jul-2006 18:03:35   

Otis wrote:

Richard, I've created a video for you which illustrates what I meant:

http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=6410

(I had to try out and learn how to use DemoBuilder anyway wink )

How would you modify the method suggested in the video to add a ControlParameter optionally. The original request was to either show all results or a subset of results depending on the value of the drop-down.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 27-Jul-2006 19:11:04   

What exactly do you mean with 'optionally' ?

Frans Bouma | Lead developer LLBLGen Pro
drice avatar
drice
User
Posts: 2
Joined: 27-Jul-2006
# Posted on: 27-Jul-2006 21:10:42   

Using the original code example:


if (DropDownList1.SelectedValue != "-1" && DropDownList1.SelectedValue != "")
{
    e.Filter.PredicateExpression.Add((StockOrderFields.OrderStatusId == DropDownList1.SelectedValue));
    da.FetchEntityCollection(e.ContainedCollection, e.Filter, 0, e.Sorter, e.PrefetchPath);
}
else
{
    da.FetchEntityCollection(e.ContainedCollection, e.Filter, 0, e.Sorter, e.PrefetchPath);
}

I assume this code block means, if the select's value is not "" then add the filter, otherwise don't add it at all. Presumably the select looked something like this:


<option value ="" selected="selected">All</option>
<option value ="Germany">Germany</option>
<option value ="USA">USA</option>
<option value ="UK">UK</option>

So if the select box was on the All line, then the filter would not be applied and not limit the data any. Specifically in the example in your video I was curious if there is a way to do this sort of option filtering.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 28-Jul-2006 15:45:10   

I was curious if there is a way to do this sort of option filtering.

Would you please elaborate more, how and where do you want this to be implemented?

csmac3144
User
Posts: 74
Joined: 12-Sep-2007
# Posted on: 27-Oct-2007 05:06:58   

This question was never answered, and it is very basic!

How can I bind a dropdown box so that one of the items is just blank (no value, so no filtering applied).

I tried putting % and * in there but these did not work.

I am doing a simple Northwind filter with a dropdown with some countries. I want one of the options to be "All Countries". What do I put in the Value for that item in the dropdown?

Can this be done declaratively at all?

Thanks!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 27-Oct-2007 06:59:21   

As far as I know that isn't possibly using fully declarative. You can do one of the following:

A. Use livepersistence=false and add filters depending upon the DropDownList selection.

B. Use livepersistence=true and handle the DropDownList SelectValueChange event, something like this http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7480

Hope helpful wink

David Elizondo | LLBLGen Support Team
csmac3144
User
Posts: 74
Joined: 12-Sep-2007
# Posted on: 28-Oct-2007 07:40:34   

Yes it was helpful, David.

Thanks!