LLBProGenDataSource - "All" option with LivePersistence

Posts   
 
    
jshallard
User
Posts: 62
Joined: 23-Mar-2005
# Posted on: 07-Sep-2006 17:11:01   

We are using a dropdown as an input parameter for an LLBProGenDataSource, E.G:

Customers:
 <asp:DropDownList ID="ddl" runat="server" AutoPostBack="True">
    <asp:ListItem>Spain</asp:ListItem>
    <asp:ListItem>Germany</asp:ListItem>
</asp:DropDownList><br />

<cc1:LLBLGenProDataSource ID="llblgenDS2" runat="server"
    CacheLocation="Session" DataContainerType="EntityCollection" 
    EnablePaging="True"
    EntityCollectionTypeName="NWTest.CollectionClasses.OrderCollection, NWTest"
    LivePersistence="True">
    <SelectParameters>
        <asp:ControlParameter ControlID="ddl" Name="ShipCountry" PropertyName="SelectedValue" Type="String" />
    </SelectParameters>
</cc1:LLBLGenProDataSource>


This works well when we would like to filter our customer list by Country. However, we often would like an "All" option, for example:

Customers:
 <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True">
    <asp:ListItem>All</asp:ListItem>
    <asp:ListItem>Spain</asp:ListItem>
    <asp:ListItem>Germany</asp:ListItem>
</asp:DropDownList><br />

Is there a way to still use the simple LivePersistence model, but implement an all option (that will simply not use the filter)?

Thanks for any help

jshallard
User
Posts: 62
Joined: 23-Mar-2005
# Posted on: 07-Sep-2006 18:53:27   

I have found a solution by putting the following code in the codebehind page (example code below for anyone who is looking to do the same). This method also allows you to specify parameters in the ASPX page as well.

I would be interested to hear if anyone has an alternative method

        protected void Page_Load(object sender, EventArgs e)
        {
            this.DataSource1.Refetch = true;
        }

        protected void uxDdl_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(this.uxDdl.SelectedValue == "all")
            {
                this.uxGridView.DataBind();
            }
            else if(this.uxDdl.SelectedValue == "Spain")
            {
                this.DataSource1.SelectParameters.Add(new Parameter("Country", TypeCode.String, "Spain "));
            }
            else if(this.uxDdl.SelectedValue == "Germany")
            {
                this.DataSource1.SelectParameters.Add(new Parameter("Country", TypeCode.String, "Germany "));
            }
        }