NetTiers GridViewSearchPanel

One of the nifty controls that NetTiers generates is the GridViewSearchPanel which gives you a nice simple search UI to filter the results in a GridView.

Unfortunately, its not exactly obvious how to setup this control.  On the surface it looks simple, you just drop a GridView, GridViewSearchPanel, and a NetTiers datasource control on to the page and connect the dots via their  XXXXControlID attributes:

<data:ProductDataSource ID="ProductDS" runat="server"
        EnablePaging="true" EnableSorting="true"
        SelectMethod="GetPaged">
</data:ProductDataSource>

<data:GridViewSearchPanel ID="SearchPanel" runat="server"
        BusinessEntityType="Test.Product"
        GridViewControlID="SearchResultsView" />

<asp:GridView ID="SearchResultsView" runat="server"
        DataSourceID="ProductDS"
        AllowPaging="true" AllowSorting="true" PageSize="20" />

This all compiles, but unfortunately we missed one thing.  In order to enable the ProductDataSource to add the SearchPanel's filter criteria, we need to add a dummy parameter named "WhereClause" that the SearchPanel can populate with the search criteria.  Also, you will need a similar "OrderByClause" parameter to enable gridview sorting.  So the final ProductDataSource control should be declared like this:

<data:ProductDataSource ID="ProductDS" runat="server"
        EnablePaging="true" EnableSorting="true"
        SelectMethod="GetPaged">
    <Parameters>
        <data:CustomParameter Name="WhereClause"
                ConvertEmptyStringToNull="false" />
        <data:CustomParameter Name="OrderByClause" Value=""
                ConvertEmptyStringToNull="false" />
    </Parameters>
</data:ProductDataSource>

It's a simple change, but it took me far too long to figure it out, so I hope this saves someone else (or myself) time if you run across this.

If you havent tried NetTiers and CodeSmith, you really should go download them and spin up a quick Northwind test project.   They recently released NetTiers v2.0 which has some outstanding improvements over the previous incarnations.  The documentation is still coming along, but you can typically solve any problem via the the forums on CodeSmithTools.com, samples & walkthroughs on NetTiers.com, and the growing documentation on wiki.NetTiers.com

1 Comment

  • Been using NetTiers for a couple of months on a side project and I must admit the more I find, the bigger my smile...

    I was fairly giddy since I just began another iteration which includes a search feature.

    This find is a great feature!
    It would be nice to see this control evolve to allow explicit field declarations in design time to allow a collection of possible search fields, each with their own "which" options!

    Beauty Lance, Hats off NetTiers!

    RA

Comments have been disabled for this content.