views:

595

answers:

1

I have the following (sample)code to filter search results from a LLBLGen data source:

IPredicateExpression firstFilter = new PredicateExpression();
firstFilter.Add(new FieldLikePredicate(CustomerFields.FirstName, null, txtSearchFirst.Text.Trim() + "%"));
llbldsCustomer.FilterToUser = firstFilter;
llbldsCustomer.DataBind();
gridview1.DataBind();

This works fine and filters the results when I trigger this code. However, if I add a second filter, I have to press invoke the code twice before I see results. Below is the snippet with 2 filters:

IPredicateExpression firstFilter = new PredicateExpression();
firstFilter.Add(new FieldLikePredicate(CustomerFields.FirstName, null, txtSearchFirst.Text.Trim() + "%"));
firstFilter.Add(new FieldLikePredicate(CustomerFields.LastName, null, txtSearchLast.Text.Trim() + "%"));
llbldsCustomer.FilterToUser = firstFilter;
llbldsCustomer.DataBind();
gridview1.DataBind();

The issue is fine for every search after the first one; however, I need it to work on the first one.

UPDATE: The code is located in an ASP.Net Button Click event. There is no code in the Page Load event block that affects this data source either.

Any ideas?

A: 

I am unable to duplicate the behavior you are seeing in a simple test case (see below). Also, unless you are using parameter binding on the datasource, you shouldn't have to call DataBind on the DataSource control but only on the GridView.


Test Case:

DB contains 1 table Customer with two varchar(50) fields: FirstName and LastName.

Default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestWebApp1._Default" %>
<%@ Register Assembly="SD.LLBLGen.Pro.ORMSupportClasses.NET20" Namespace="SD.LLBLGen.Pro.ORMSupportClasses" TagPrefix="llblgenpro" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
        <br />
        <br />
    <asp:GridView ID="CustomersGridView" runat="server" DataSourceID="dsCustomers">
    </asp:GridView>
    </div>
    <llblgenpro:LLBLGenProDataSource ID="dsCustomers" runat="server" 
        DataContainerType="EntityCollection" 
        EntityCollectionTypeName="TestWebApp1Framework.CollectionClasses.CustomerCollection, TestWebApp1Framework">
    </llblgenpro:LLBLGenProDataSource>
    </form>
</body>
</html>

Default.aspx.cs:

using System;
using SD.LLBLGen.Pro.ORMSupportClasses;
using TestWebApp1Framework.HelperClasses;

namespace TestWebApp1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Button1_Click(object sender, EventArgs e)
        {
            var filter = new PredicateExpression();
            filter.Add(new FieldLikePredicate(CustomerFields.FirstName, null, TextBox1.Text.Trim() + "%"));
            filter.AddWithOr(new FieldLikePredicate(CustomerFields.LastName, null, TextBox1.Text.Trim() + "%"));
            dsCustomers.FilterToUse = filter;
            dsCustomers.DataBind();
            CustomersGridView.DataBind();
        }
    }
}

Test Results: Loading this page initially shows all customers. Entering the letter A into the textbox and clicking the button shows a list of all customers whose first name or last name starts with A. This shows that both filters are working correctly.

David Archer
Updated the question to include the fact that the code is in a Button.Click event and there is nothing in the Page.Load method.
JamesEggers
Hmm, just cleared all of my cache and cleaned the build and tried again and it seems to be working now. Weird. Thanks for the response and the test information!
JamesEggers