CodeSmith Community
Your Code. Your Way. Faster!

EntityDataSource.Filter ~ DataList

Latest post 12-14-2006 5:02 PM by Ryan Anderson. 12 replies.
  • 12-13-2006 1:36 PM

    EntityDataSource.Filter ~ DataList

    *blanket disclaimer, don't slap me...*
    New to NetTiers....

    I am attempting to "Filter" data from an EntityDataSource via user input (textBox) and am for certain I am missing something blatant here...

    <asp:TextBox ID="TermTextBox" runat="server" Columns="45" MaxLength="50"></asp:TextBox><asp:Button runat="server" ID="SearchButton" Text="search" OnClick="SearchButton_Click" />
    <atlas:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server">
    <atlas:AutoCompleteProperties Enabled="true" MinimumPrefixLength="1" TargetControlID="TermTextBox" ServicePath="~/Services/GlossaryService.asmx" ServiceMethod="GetFilteredTerms" />
    </atlas:AutoCompleteExtender>
    <br />
    <br />
    <table style="width: 100%;">
    <tr>
    <td style="width: 600px;">
    <asp:DataList runat="server" ID="GlossaryDataList" DataSourceID="GlossaryDataSource1">
    <ItemTemplate>
    <strong><%# Eval("Term") %></strong> - <%# Eval("Definition") %>
    <br />
    <br />
    <hr style="width: 100%; height: 1px; border: dotted 1px #C0C0C0;" />
    </ItemTemplate>
    </asp:DataList>
    <data:GlossaryDataSource runat="server" ID="GlossaryDataSource1" SelectMethod="GetAll">
    </data:GlossaryDataSource>
    <br />
    <br />
    </td>
    <td style="width: 150px;">
    <atlas:UpdateProgress ID="GlossaryProgressPanel" runat="server">
    <ProgressTemplate>
    <img src="../Images/loading.gif" alt="Loading" />One moment... The Glossary is loading.
    </ProgressTemplate>
    </atlas:UpdateProgress>
    </td>
    </tr>
    </table>

    protected void SearchButton_Click(object sender, EventArgs e)
    {
    GlossaryDataSource1.Filter = string.Format("Term LIKE '{0}%'", TermTextBox.Text);
    }


    The page loads great, I have data, the AutoComplete Service kicking like a charm, have even eliminated it to test bare bones, postback SearchButton_Click method fires, Filter property is set for GlossaryDataSource1 when stepping through code, but data is not filtered...

    I even tried disabling viewstate on the DataList and calling both the GlossaryDataSource1.DataBind() and the GlossaryDataList.DataBind() methods after applying the Filter to the DataSource, all no go. I even saw something about Filter and EnablePaging and EnableSorting set to false in intellisense of the .Filter method, no avail.

    It has to be something right in front of me, I can feel it...

    Many thanks in advance...
    RA

    • Post Points: 45
  • 12-13-2006 2:13 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,880

    Re: EntityDataSource.Filter ~ DataList

    Ryan Anderson,

    Can you try the following:

    protected void SearchButton_Click(object sender, EventArgs e)
    {
    GlossaryDataSource1.Filter = string.Format("Term LIKE '{0}%'", TermTextBox.Text);

    GlossaryDataList.DataBind();
    }

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 35
  • 12-13-2006 2:39 PM In reply to

    Re: EntityDataSource.Filter ~ DataList

    Mike123,
    Ahhh... Vagueness (sp.)

    No data displays at all when I type in single or multiple letters that exists in the data;

    example: the following records exist in the data on intial page load: Maker, Market Rent, Market Study, Market Value.

    When I type in "m" or "M" (thought it might be a case issue at first) or even "Market Study" and click the 'SearchButton' no data displays. The SearchButton_Click event fires and the .Filter property of the DataSource is set properly, yet nada. :(

    Any idear's?
    Thanks again,
    Ryan

    • Post Points: 35
  • 12-13-2006 4:43 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,880

    Re: EntityDataSource.Filter ~ DataList

    Ryan,

    Have you stepped through the code, do you see TermTextBox.Text has a value assigned?

     

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 60
  • 12-13-2006 5:13 PM In reply to

    Re: EntityDataSource.Filter ~ DataList

    Roger that.

    I even "watch" in both the Watch window and Autos window (I know redundant) the GlossaryDataSource1.Filter value change to "Term LIKE 'M%'" as well.
    Don't break your neck Mike, this has to be something assinine on my part.

    I did however pull out all AJAX (AutoCompleteExtender, UpdatePanel, UpdateProgress controls) and left nothing but the SearchButton, GlossaryDataList, and GlossaryDataSource and still the same problem, no data returned after filter.

    I even changed;
    String.Format("Term Like '{0}%'", TermTextBox.Text);
    To:
    String.Format("Termsss Like '{0}%'", TermTextBox.Text);

    To get an error of course since the column Termsss doesn't exist.

    Interesting to me is that I can enter nothing (I mean leave blank) into the TermTextBox, which should logically return all records and nothing comes up.

    I can query the database with this same filter direcly and I do get records not sure what I am doing.
    Sounds like a personal issue if you ask me... LOL...



     

    • Post Points: 5
  • 12-13-2006 5:50 PM In reply to

    Re: EntityDataSource.Filter ~ DataList

    I even took it a step further and implemented a "Clear Filter" button to set the GlossaryDataSource.Filter = "";
    Here is the code in its entirty again:
    <atlas:UpdatePanel ID="GlossaryUpdatePanel" runat="server" Mode="Always">
    <ContentTemplate>
    To filter begin typing text into the text box below and a list of possible matched will display dynamically.<br />
    <asp:TextBox ID="TermTextBox" runat="server" Columns="45" MaxLength="50"></asp:TextBox><asp:Button runat="server" ID="SearchButton" Text="filter" OnClick="SearchButton_Click" />&nbsp;<asp:Button runat="server" ID="ClearSearchButton" Text="clear filter" OnClick="ClearSearchButton_Click" Enabled="false" />
    <atlas:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server">
    <atlas:AutoCompleteProperties Enabled="true" MinimumPrefixLength="1" TargetControlID="TermTextBox" ServicePath="~/Services/GlossaryService.asmx" ServiceMethod="GetFilteredTerms" />
    </atlas:AutoCompleteExtender>
    <br />
    <br />
    <table style="width: 100%;">
    <tr>
    <td style="width: 600px;">
    <asp:DataList runat="server" ID="GlossaryDataList" DataSourceID="GlossaryDataSource1">
    <ItemTemplate>
    <strong><%# Eval("Term") %></strong> - <%# Eval("Definition") %>
    <br />
    <br />
    <hr style="width: 100%; height: 1px; border: dotted 1px #C0C0C0;" />
    </ItemTemplate>
    </asp:DataList>
    <data:GlossaryDataSource runat="server" ID="GlossaryDataSource1" SelectMethod="GetAll" EnablePaging="false">
    </data:GlossaryDataSource>
    <br />
    <br />
    </td>
    <td style="width: 150px;">
    <atlas:UpdateProgress ID="GlossaryProgressPanel" runat="server">
    <ProgressTemplate>
    <img src="../Images/loading.gif" alt="Loading" />One moment... The Glossary is loading.
    </ProgressTemplate>
    </atlas:UpdateProgress>
    </td>
    </tr>
    </table>
    </ContentTemplate>
    </atlas:UpdatePanel>

    protected void SearchButton_Click(object sender, EventArgs e)
    {
    ClearSearchButton.Enabled =
    true;
    GlossaryDataSource1.Filter =
    String.Format("Term LIKE '{0}%'", TermTextBox.Text);
    GlossaryDataList.DataBind();
    }

    protected void ClearSearchButton_Click(object sender, EventArgs e)
    {
    ClearSearchButton.Enabled =
    false;
    TermTextBox.Text =
    "";
    GlossaryDataSource1.Filter =
    "";
    GlossaryDataList.DataBind();
    }

    What I found interesting is that the ClearSearchButton_Click event works great. After I attempt a "Filter" (which renders the DataList with no data) all the data properly displays again...

    I am using CodeSmith 3.2 and netTiers v2.0.0.387 if that be of any use. I also rebuilt/ compiled/ generated the application as well. I also think I have tried every variation of enabling and disabling viewstate for all controls on the page.

    Clueless over here.
    Thanks... 

    • Post Points: 35
  • 12-13-2006 7:08 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,880

    Re: EntityDataSource.Filter ~ DataList

    Ryan,

    Sorry it's totally slipped my mind Tongue Tied, you should fine just use asterisk instead of percentage when you construct your LIKE clause

    protected void SearchButton_Click(object sender, EventArgs e)
    {
    ClearSearchButton.Enabled =
    true;
    GlossaryDataSource1.Filter =
    String.Format("Term LIKE '{0}*'", TermTextBox.Text);
    GlossaryDataList.DataBind();
    }

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    Filed under: ,
    • Post Points: 60
  • 12-13-2006 8:59 PM In reply to

    Re: EntityDataSource.Filter ~ DataList

    LMAO!!!

    I told you it was something assinine right in front of my face... I think I saw that in the wiki too but it didn't sink in...

    No worries, I am just glad that there was someone on "The Other Side" of the forum firing back with the assist!

    Works like a champ!

    Many thanks Mike!
    RA

    • Post Points: 5
  • 12-13-2006 9:19 PM In reply to

    Re: EntityDataSource.Filter ~ DataList

    Interesting thing about it is that it is when typing an a single letter the filter returns all Glossary Terms that have that letter anywhere in the Term (excluding the first letter).

    Example: If I Type "Ma" and click the search button it will list
    Returns ~
    Small Cap, Small Door

    Not ~
    Maker, Market Rent, Market Study, Market Value
    Like I assumed it would.

    I attempting to get filtered records that start with the typed letter/ letters. Is this functionality available via this method?

    I think I may have to use a custom query instead, which is alright by me I guess... 

    Once again many thanks,
    RA

     

    • Post Points: 35
  • 12-14-2006 2:16 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 922
    • Points 34,710

    Re: EntityDataSource.Filter ~ DataList

    Reply |Contact |Answer

    Ryan,

    Have you tried using the declarative filters?

    i.e. change your datasources select method to Find and then specify parameters in a similar fashion to code below

    SelectMethod="Find" >
    <Parameters>
    <data:SqlParameter Name="Parameters" >
    <Filters>
    <data:GlossaryFilter Column="Term" ControlID="TermTextBox" ComparisionType="Contains" />
    </Filters>
    </data:SqlParameter>
    </Parameters>

    or using a filter predicate in the OnSelected event of your data source like...

    private void GlossaryDataSource_Selected( object sender, ObjectDataSourceStatusEventArgs e )
    {
    TList<Glossary> glossaryList = e.ReturnValue as TList<Glossary>;
    glossaryList.ApplyFilter(
    delegate( Glossary x )
    {
    return ( x.Term == TermTextBox.text )
    );
    } );
    }

    HTH

    swin

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 35
  • 12-14-2006 1:53 PM In reply to

    • Meech
    • Top 50 Contributor
    • Joined on 02-14-2006
    • Posts 98
    • Points 2,788

    Re: EntityDataSource.Filter ~ DataList

    The downside to this is that it sends a bunch of custom sql, creates a temporary table, etc when a simple where clause would suffice.

    • Post Points: 35
  • 12-14-2006 2:44 PM In reply to

    Re: EntityDataSource.Filter ~ DataList

    If using SQL2005, and you select it when generating, it will not use the temporary table in favor for the new paging constructs in SQL Server.

    On 12/14/06, Meech <bounce-Meech@codesmithsupport.com> wrote:

    The downside to this is that it sends a bunch of custom sql, creates a temporary table, etc when a simple where clause would suffice.






    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 35
  • 12-14-2006 5:02 PM In reply to

    Re: EntityDataSource.Filter ~ DataList

    Beauty!

    You guys are wonderful! I have it in an AJAX UpdatePanel right... Put it up on my production server after I was done tinkering and it flows flawlessly!

    I used the GlossaryFilter, your first example and it is just seamless... All data loads on page load (initially) my AutoCompleteExtender put a smile on my clients face, and the lack of pain in developing a cheap search tool put a smile on mine! Loving it! Total development time for Glossary Search tool (minus learning curve for me) about 30 minutes total....
    I have only been working with netTiers for a few weeks now and the more I play, the more I find it to be priceless!!!
    A solution seems to always be a stones throw away...

    I sincerely thank you guys!

    • Post Points: 15
Page 1 of 1 (13 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems