Using the LLBLGenProDataSource2's SelectParameters

Posts   
 
    
Carl J
User
Posts: 5
Joined: 28-Oct-2008
# Posted on: 29-Oct-2008 15:16:01   

I have, what I hope to be a quick and easy question regarding filtering records using the SelectParameters of the LLBLGenProDataSource2.

Before I ask, I should mention that we are using LLBLGen Pro 2.0.0.0 Final (Oct 3rd, 2006) with .Net 2.x and Sitefinity 3.2.

So, I have a GridView on my page that has it's datasource set to the Id of the LLBLGenProDataSource2. When I run it as is, all of the records are returned, and I'm able to sort and page. So far, so good.

Now I'm trying to add a filter to the grid so that I can show only records that contain the text that's provided (using a LIKE). There's also a couple of dropdown lists that I also want to use to filter, but for now I only have the textbox.

I've added a SelectParameter to the LLBLGenProDataSource2, set its controlId to the Id of the textbox, the defaultvalue is set to '', the name is set to "title" and the propertyname is "Text". Also, currently I removed the livepersistence attribute (it was previously in there, set to true).

So what I'm wondering is, if I place a button on my form, what do I need to do to get the button to tell the LLBLGenProDataSource2 to re-get the data, and filter it by what's in the textbox? I've looked in the helpfile ("[b]Generated code - Databinding with ASP.NET 2.0, Adapter[/b]"), but either I couldn't find what I needed, or just don't understand the help file.

I've even set the text of the textbox to something and ran the application, but all of the records are still returned.

Is there something in the code behind that I should be doing? In the Button's click eevnt, should I be telling the GridView to DataBind()? I've tried this, but this doesn't seem to work either.

Here's the markup that I have so far:


<llblgenpro:llblgenprodatasource2 id="LLBLGenProDataSource2_1" runat="server" adaptertypename="SMDHU.Website.Module.Parenting.LLBL.DatabaseSpecific.DataAccessAdapter, SMDHU.Website.Module.Parenting.LLBLDBSpecific" datacontainertype="EntityCollection" entityfactorytypename="SMDHU.Website.Module.Parenting.LLBL.FactoryClasses.ParentingPagesSearchEntityFactory, SMDHU.Website.Module.Parenting.LLBL" enablepaging="True">
    <selectparameters>
        <asp:controlparameter controlid="txtParentingPageTitle" defaultvalue="''" name="title" propertyname="Text" />
    </selectparameters>
</llblgenpro:llblgenprodatasource2>

<telerik:radgrid id="grdPages" datasourceid="LLBLGenProDataSource2_1" allowpaging="true" allowsorting="true" runat="server">
                    <pagerstyle mode="NextPrevNumericAndAdvanced" nextpagetext="&amp;gt;" PrevPageText="&amp;lt;" AlwaysVisible="true" />
                    <clientsettings enablepostbackonrowclick="false">
                        <selecting allowrowselect="false" />
                    </clientsettings>
                    <mastertableview headerstyle-backcolor="#2C6FD1" allowsorting="true" datakeynames="PageId" commanditemdisplay="None" headerstyle-height="10px" visible="true" autogeneratecolumns="false">
                        <columns>
                            <telerik:gridbuttoncolumn buttontype="LinkButton" commandname="Select" text="Edit" headerstyle-width="25" headertext="" />
                            <telerik:gridboundcolumn datafield="Title" headertext="Title" />
                        </columns>
                    </mastertableview>
                </telerik:radgrid>

Any help in the right direction would be greatly appreciated.

Thanks, Carl J http://www.carlj.ca

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 29-Oct-2008 16:28:37   

Please try the following, and take care of the case sensetivity.

<selectparameters>
<asp:ControlParameter ControlID="txtParentingPageTitle" Name="Title" PropertyName="Text" Type="String" />
</selectparameters>

Also you are using an old build, for v.2.0 the most recent build goes to Dec 2007.

Is there something in the code behind that I should be doing? In the Button's click eevnt, should I be telling the GridView to DataBind()?

Me too, I would have used GridView.DataBind(). Just try the above code and get the latest release first.

Carl J
User
Posts: 5
Joined: 28-Oct-2008
# Posted on: 29-Oct-2008 18:08:37   

Awesome, thanks a lot Walaa.

It looks like it was just something dumb on my part. It's always the little things that seem to get you. The issue was caused by the small "t" in "Title".

There is one small issue with this. No records are displayed the first time the Grid is loaded, and I have to type an exact title in the textbox (which I understand why, just trying to figure out how to change it to a LIKE '% Title %').

As for the version, yes we are using an older build for now. They/we haven't updated to the newest version of 2.0. We will be using the newest version of LLBLGen Pro soon for some new stuff that we're working on.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Oct-2008 08:02:39   

Carl wrote:

There is one small issue with this. No records are displayed the first time the Grid is loaded, and I have to type an exact title in the textbox (which I understand why, just trying to figure out how to change it to a LIKE '% Title %').

Yep. That's by design. You cannot use SelectParameters in a "like" filtering way. In other words, 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

David Elizondo | LLBLGen Support Team
Carl J
User
Posts: 5
Joined: 28-Oct-2008
# Posted on: 30-Oct-2008 13:50:36   

Hi daelmo, thanks for the reply.

After receiving the reply from Walaa yesterday, I came across that link that you sent, and have been trying to write a variation of it, with little success.

The issue that I'm having is with the textbox. For me to find all results that contain the string in the textbox, would I have to write my own Get method using a 'FieldLikePredicate' to retrieve the data from the database, then pass that EntityCollection to the 'LLBLGenProDataSource'?

Or, can I add a LIKE when using the code from the link you provided, when adding to the DataSource.SelectParameters?

Thanks once again, Carl J

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 30-Oct-2008 21:29:11   

would I have to write my own Get method using a 'FieldLikePredicate' to retrieve the data from the database, then pass that EntityCollection to the 'LLBLGenProDataSource'?

Exactly that - the DataSouce.SelectParameters will not let you do "LIKE" style filtering.

Carl J
User
Posts: 5
Joined: 28-Oct-2008
# Posted on: 03-Nov-2008 22:09:17   

Ok, so the SelectParameters doesn't allow you to select using a partial string.

Is there anyway, other than me writing something to fetch my own data, that will allow me to return records that contain a string, instead of an exact match?

Thanks, Carl J

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 04-Nov-2008 05:28:34   

Unfortunelly no. You have to write the filter at code-behind. You have to apply the filter to yourLLBLGenDataSource.FilterToUse.

David Elizondo | LLBLGen Support Team
Carl J
User
Posts: 5
Joined: 28-Oct-2008
# Posted on: 04-Nov-2008 14:34:21   

Awesome, that's what I was looking for (but didn't see).

Thanks daelmo Carl J www.carlj.ca