locked
Extended Dynamic Data Filtering RRS feed

  • Question

  • User1024101778 posted

    I have been working with the Dynamic Data  Framework for a couple months and just recently finished a project where we implement it.  I believe it Dynamic Data in conjunction with LINQ-to-SQL reduced our development time by about 40%.  There was a need for advanced filtering on the project so I wrote some Dynamic Data filtering controls following the Dynamic Data model. 

    The filtering framework extension allows developers to create DynamicFilterControls which mimic the model of the DynamicFieldControls for different data types or RenderHints. I have had to extend & modify a few things around the LinqDataSource and LinqDataSourceView to enable rich query capabilities.  This is done by providing LambdaExpressions to the LinqDataSourceView.  Below is a code example and picture to demonstrate the functionality.  I have posted several blog posts about the controls and have made the code available on my blog, http://blogs.catalystss.com/blogs/josh_heyse/archive/tags/Dynamic+Data/default.aspx.  

    <cc1:DynamicFilterForm DataSourceID="GridDataSource" runat="Server" ID="DynamicFilterForm1">
    <FilterTemplate>
    <div>
    Search
    </div>
    <table>
    <tr>
    <td>
    Name:
    </td>
    <td>
    <cc1:DynamicFilterControl ID="DynamicFilterControl3" runat="server" DataField="Name" FilterMode="Contains" />
    </td>
    <td>
    Product Number:
    </td>
    <td>
    <cc1:DynamicFilterControl ID="DynamicFilterControl5" runat="server" DataField="ProductNumber" FilterMode="Contains" />
    </td>
    <td>
    Class:
    </td>
    <td>
    <cc1:DynamicFilterControl ID="DynamicFilterControl6" runat="server" DataField="Class" FilterMode="Contains" />
    </td>
    <td rowspan="2" valign="top">
    Product Model:
    </td>
    <td rowspan="2" valign="top">
    <cc1:DynamicFilterControl ID="DynamicFilterControl7" runat="server" DataField="ProductModel" FilterMode="MultiSelect" />
    </td>
    <td rowspan="2" valign="top">
    <asp:LinkButton runat="server" CommandName="Search">Search</asp:LinkButton><br />
    <asp:LinkButton runat="server" CommandName="Clear">Clear</asp:LinkButton><br />
    <asp:LinkButton runat="server" CommandName="Browse">Browse</asp:LinkButton>
    </td>
    </tr>
    <tr>
    <td>
    List Price:
    </td>
    <td>
    <cc1:DynamicFilterControl ID="DynamicFilterControl1" runat="server" DataField="ListPrice" FilterMode="Range" />
    </td>
    <td>
    Color:
    </td>
    <td>
    <cc1:DynamicFilterControl ID="DynamicFilterControl4" runat="server" DataField="Color" FilterMode="Contains" />
    </td>
    <td>
    Subcategory:
    </td>
    <td>
    <cc1:DynamicFilterControl ID="DynamicFilterControl2" runat="server" DataField="ProductSubcategory" />
    </td>
    </tr>
    </table>
    </FilterTemplate>
    </cc1:DynamicFilterForm>
      DynamicFilterForm
    Thursday, April 10, 2008 1:53 PM

All replies

  • User-853298616 posted

    This looks really interesting. I need some searching capabilities in my project and this seems like the approach I need.

    Thks! 

    Thursday, June 5, 2008 11:02 AM
  • User1659040753 posted

    Duplicate

    Friday, June 6, 2008 7:16 PM
  • User1659040753 posted

    Duplicate

    Friday, June 6, 2008 7:16 PM
  • User1659040753 posted

    Great work here!  Thanks for making this public.  I know I will be needing to use this in the future.

    Sorry about the duplicate posts. 

    Friday, June 6, 2008 7:17 PM
  • User1180034286 posted

    Looks very flexible thanks for this!

     

    Sunday, June 8, 2008 5:30 AM
  • User-853298616 posted

    OK, I've been trying to get this to work and so far I managed to get all the filter templates to render correctly and all that.

    But now when I do a simple search it simply doesn't do anything. The same records are returned as if I had done nothing. And no error shows up.

    I know this is a longshot, and I'm not giving a lot of information about the problem, but since no error pops up, I'm kind of lost here.

    Here's what I did:

    1. Downloaded the code from here;
    2. Copied the DynamicData folder (where all the classes are) to the Code folder of my app;
    3. Copied the FilterTemplates to a DynamicData/FilterTemplates folder (right next to the FieldTemplates and CustomPages folder);
    4. Added some <cc1:DynamicFilterForm> to my custom List.aspx file.

    Have I done anything wrong that may be keeping it from working?

    Thks.
     

    Tuesday, June 10, 2008 12:33 PM
  • User1024101778 posted

    You may be missing the runat=server tag from the DynamicFilterForm.  Can you post your entire aspx page here?

    Tuesday, June 10, 2008 1:15 PM
  • User-853298616 posted

    The runat="server" is there. Here's the .aspx page: 

    <%@ Page Language="C#" MasterPageFile="~/Site.master" CodeBehind="List.aspx.cs" Inherits="integrationUTLweb.AgregacaoList" %>
    
    <%@ Register src="~/DynamicData/Content/GridViewPager.ascx" tagname="GridViewPager" tagprefix="asp" %>
    <%@ Register src="~/DynamicData/Content/FilterUserControl.ascx" tagname="DynamicFilter" tagprefix="asp" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true" />
    
        <h2><%= table.DisplayName%></h2>
    
        <asp:ScriptManagerProxy runat="server" ID="ScriptManagerProxy1" />
    
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
                    HeaderText="List of validation errors" />
                <asp:DynamicValidator runat="server" ID="GridViewValidator" ControlToValidate="GridView1" Display="None" />
    
    
    <cc1:DynamicFilterForm DataSourceID="GridDataSource" runat="Server" ID="DynamicFilterForm1">
            <FilterTemplate>
                <div>
                    Search
                </div>
                <table>
                    <tr>
                        <td>
                            Número do Processo:
                        </td>
                        <td>
                            <cc1:DynamicFilterControl ID="DynamicFilterControl3" runat="server" DataField="NumeroProcesso"
                                FilterMode="Contains" />
                        </td>
                        <td>
                            Área da Agregação:
                        </td>
                        <td>
                            <cc1:DynamicFilterControl ID="DynamicFilterControl5" runat="server" DataField="AreaAgregacao"
                                FilterMode="Contains" />
                        </td>
                        <td>
                            Categoria:
                        </td>
                        <td>
                            <cc1:DynamicFilterControl ID="DynamicFilterControl6" runat="server" DataField="Categoria"
                                FilterMode="Contains" />
                        </td>
                        <td rowspan="2" valign="top">
                            Escola:
                        </td>
                        <td rowspan="2" valign="top">
                            <cc1:DynamicFilterControl ID="DynamicFilterControl7" runat="server" DataField="EscolaUTL1"
                                FilterMode="MultiSelect" />
                        </td>
                        <td rowspan="2" valign="top">
                            <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Search">Search</asp:LinkButton><br />
                            <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Clear">Clear</asp:LinkButton><br />
                            <asp:LinkButton ID="LinkButton3" runat="server" CommandName="Browse">Browse</asp:LinkButton>
                        </td>
                    </tr>
                </table>
            </FilterTemplate>
        </cc1:DynamicFilterForm>
    
    
    
                <h3>Filtros</h3>
                <asp:FilterRepeater ID="FilterRepeater" runat="server">
                    <ItemTemplate>
                        <asp:Label runat="server" Text='<%# Eval("DisplayName") %>' AssociatedControlID="DynamicFilter$DropDownList1" />
                        <asp:DynamicFilter runat="server" ID="DynamicFilter" OnSelectedIndexChanged="OnFilterSelectedIndexChanged" />
                    </ItemTemplate>
                    <FooterTemplate><br /><br /></FooterTemplate>
                </asp:FilterRepeater>
          
    
                <asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource"
                    AllowPaging="True" AllowSorting="True" CssClass="gridview"
                    AutoGenerateColumns="false" EnableQueryStringSelection="True">
                    <Columns>
                        <asp:DynamicField DataField="Requerente1"></asp:DynamicField>
                        <asp:DynamicField DataField="EscolaUTL1"></asp:DynamicField>
                        <asp:DynamicField DataField="DataEntradaProcesso"></asp:DynamicField>
                        <asp:DynamicField DataField="Responsavel"></asp:DynamicField>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:HyperLink ID="EditHyperLink" runat="server"
                                    NavigateUrl='<%# table.GetActionPath(PageAction.Edit, GetDataItem()) %>'
                                Text="Edit" /> <asp:LinkButton ID="DeleteLinkButton" runat="server" CommandName="Delete"
                                    CausesValidation="false" Text="Delete"
                                    OnClientClick='return confirm("Are you sure you want to delete this item?");'
                                /> <asp:HyperLink ID="DetailsHyperLink" runat="server"
                                    NavigateUrl='<%# table.GetActionPath(PageAction.Details, GetDataItem()) %>'
                                    Text="Details" />
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
    
                    <PagerStyle CssClass="footer"/>        
                    <PagerTemplate>
                        <asp:GridViewPager runat="server" />
                    </PagerTemplate>
                    <EmptyDataTemplate>
                        There are currently no items in this table.
                    </EmptyDataTemplate>
                </asp:GridView>
    
                <asp:LinqDataSource ID="GridDataSource" runat="server" EnableDelete="true">
                    <WhereParameters>
                        <asp:DynamicControlParameter ControlID="FilterRepeater" />
                    </WhereParameters>
                </asp:LinqDataSource>
    
                <br />
    
                <div class="bottomhyperlink">
                    <asp:HyperLink ID="InsertHyperLink" runat="server"><img runat="server" src="~/DynamicData/Content/Images/plus.gif" alt="Insert new item" />Insert new item</asp:HyperLink>
                </div>
                
            </ContentTemplate>
        </asp:UpdatePanel>
    </asp:Content>
     

     
    Tuesday, June 10, 2008 1:22 PM
  • User1024101778 posted

    The reason you aren't seeing an exception is that the control is inside of a update panel and ajax is swallowing the exception.  If you are using IE you will see a script error on page in the left hand  side of  the status bar.  A better approach is to comment out the UpdatePanel and ContentTemplate, the exception will be shown as usual.

    Tuesday, June 10, 2008 1:38 PM
  • User1641955678 posted

    Please see my post for details on dealing with errors when AJAX is on.

    David

    Tuesday, June 10, 2008 1:45 PM
  • User-853298616 posted

     I already had EnablePartialRendering="false" in Site.Master, and no sign of any error.

    Tuesday, June 10, 2008 1:49 PM
  • User1024101778 posted

    Based on the code you posted, you have nested UpdatePannels then.  One in the Site.Master and another in the content page itself. 

    Tuesday, June 10, 2008 1:52 PM
  • User-853298616 posted

    Based on the code you posted, you have nested UpdatePannels then.  One in the Site.Master and another in the content page itself. 

     

    Not really, I don't have an UpdatePanel in the Site.master: 

    <%@ Master Language="C#" CodeBehind="Site.master.cs" Inherits="integrationUTLweb.Site" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Dynamic Data Site</title>
        <link href="~/css/Site.css" rel="stylesheet" type="text/css" />
        <link href="~/css/integrationUTL.css" rel="stylesheet" type="text/css" />
    </head>
    <body class="template">
    
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="false">
                <Services>
                    <asp:ServiceReference Path="~/WebServices/WebpageUtil.asmx" />
                </Services>
            </asp:ScriptManager>
            
            <div id="header">
                <div id="logo">
                    <a id="A1" runat="server" href="~/"><img id="Img1" runat="server" src="img/logoUTL.gif" alt="Universidade Técnica de Lisboa"/></a>
                </div>
                <div id="searchBox">
                    <asp:TextBox runat="server" ID="SearchTextBox">Pesquisar...</asp:TextBox>
                    <asp:Button runat="server" ID="SearchButton" Text="Pesquisar"/>
                </div>
            </div>
            <div class="clear"></div>
            
            <div id="menu"></div>
            
            <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
            </asp:ContentPlaceHolder>
        </div>
        </form>
    </body>
    </html>
      
    Tuesday, June 10, 2008 2:13 PM
  • User1641955678 posted

    I think some of the confusion comes from the fact that we used to have the update panel in the master, and in later build moved it to each page instead.  It works either way, but obviously you need to avoid mixing the old and the new as you could end up with zero or two update panels.

    David

    Tuesday, June 10, 2008 2:44 PM
  • User-853298616 posted

     Any more ideas on how to make this work? Or at least a way to find out what's the problem?

    Saturday, June 14, 2008 3:55 PM
  • User1024101778 posted

    Without the exception detail it's a little difficult to help.  I suggest trying to remove the UpdatePanel and ContentPanel, this should guarantee you receive an ASP.NET exception on post back.  I can help you from there.

    Monday, June 16, 2008 8:20 PM
  • User-853298616 posted

    I removed the UpdatePanel from the custom List.aspx page and it all works exactly the same way. No error, but the search doesn't work.

    Couldn't find any ContentPanel. Just a ContentTemplate. Also tried removing it and nothing happened. The only other similarly-named element is Content, and removing that one just breaks the whole page, as expected.

    Tuesday, June 17, 2008 12:21 PM
  • User1024101778 posted

    Oh, I just took a closer look at the code and realized that your data source is still of type LinqDataSource.  You have to change the type to DynamicLinqDataSource, please see the example below.

     

      

    <%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="List.aspx.cs"
        Inherits="DynamicDataWeb.Products.List" %>
    
    <%@ Register src="~/DynamicData/Content/GridViewPager.ascx" TagName="GridViewPager" TagPrefix="asp" %>
    <%@ Register Assembly="Catalyst.Web.DynamicData" Namespace="Catalyst.Web.DynamicData" TagPrefix="cc1" %>
    <%@ Register src="../../FilterTemplates/ColumnContains.ascx" tagname="ColumnContains" tagprefix="uc1" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
        <asp:DynamicDataManager ID="DynamicDataManager1" runat="server" EnableQueryStringSelection="true" AutoLoadForeignKeys="true" />
        <h2><%= table.DisplayName%>
        </h2>
        <asp:ScriptManagerProxy runat="server" ID="ScriptManagerProxy1" />
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true" HeaderText="List of validation errors" />
        <asp:DynamicValidator runat="server" ID="GridViewValidator" ControlToValidate="GridView1" Display="None" />
        <br />
        <br />
        <cc1:DynamicFilterForm DataSourceID="GridDataSource" runat="Server" ID="DynamicFilterForm1">
            <FilterTemplate>
                <div>
                    Search
                </div>
                <table>
                    <tr>
                        <td>
                            <uc1:ColumnContains ID="ColumnContains1" runat="server" />  
                        </td>
                        <td>
                            <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Search">Search</asp:LinkButton><br />
                        </td>
                    </tr>
                </table>
            </FilterTemplate>
        </cc1:DynamicFilterForm>
        <br />
        <asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource" AutoGenerateColumns="False"
            AutoGenerateSelectButton="True" AutoGenerateEditButton="True" AutoGenerateDeleteButton="true"
            AllowPaging="True" AllowSorting="True" EnableQueryStringSelection="True" CssClass="gridview"
            AlternatingRowStyle-CssClass="even">
            <Columns>
                <asp:DynamicField HeaderText="Name" DataField="Name" />
                <asp:DynamicField HeaderText="Product Number" DataField="ProductNumber" />
                <asp:DynamicField HeaderText="Color" DataField="Color" />
                <asp:DynamicField HeaderText="Class" DataField="Class" />
                <asp:DynamicField HeaderText="List Price" DataField="ListPrice" />
                <asp:DynamicField HeaderText="Product Subcategory" DataField="ProductSubcategory" />
                <asp:DynamicField HeaderText="Product Model" DataField="ProductModel" />
                <asp:TemplateField HeaderText="Weight">
                    <ItemTemplate>
                        <asp:DynamicControl runat="server" DataField="Weight" />
                        <asp:DynamicControl runat="server" DataField="WeightUnitMeasureCode" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <PagerStyle CssClass="Footer" />
            <PagerTemplate>
                <asp:GridViewPager ID="GridViewPager1" runat="server" />
            </PagerTemplate>
            <EmptyDataTemplate>
                There are currently no items in this table.
            </EmptyDataTemplate>
        </asp:GridView>
        <cc1:DynamicLinqDataSource ID="GridDataSource" runat="server" >
        </cc1:DynamicLinqDataSource>
        <asp:HyperLink ID="InsertHyperLink" runat="server">Insert new item</asp:HyperLink>
    </asp:Content>
    
     
    Tuesday, June 17, 2008 12:30 PM
  • User-853298616 posted

    Thks! I never noticed that "small" detail...

    It seems everything is working fine now :D 

    Tuesday, June 17, 2008 1:23 PM
  • User1641955678 posted

    I was confused at first because we used to have a DynamicLinqDataSource in earlier build.  Here, you're talking about your own custom derived data source.

    BTW, note that we added a new virtual method to LinqDataSource which should let you change the view without using reflection:

        protected virtual LinqDataSourceView CreateView();

    thanks,
    David

    Tuesday, June 17, 2008 2:57 PM
  • User1024101778 posted

    I was confused at first because we used to have a DynamicLinqDataSource in earlier build.  Here, you're talking about your own custom derived data source.

    BTW, note that we added a new virtual method to LinqDataSource which should let you change the view without using reflection:

        protected virtual LinqDataSourceView CreateView();

    thanks,
    David

     

    David,

    That's great to hear!  I don't like having to use reflection.  I will update my code to make use of the new virtual method.

     

    Tuesday, June 17, 2008 3:01 PM
  • User1641955678 posted

    I had left a message on your blog (on whichever post talks about doing reflection) about this a few days ago, but I'm not sure it made it there (waiting for approval?).  Anyway, that's all I was saying there.

    Is that the only place where you are doing private reflection?  The problem with private reflection is that it doesn't run in partial trust, preventing its use in hosting scenarios.

    David

    Tuesday, June 17, 2008 3:25 PM
  • User-853298616 posted

    I'm curious about something: what's the need for a "Search" and a "Browse"?

    From the tests I've made so far, "Browse" has no effect unless I have something selected in the "MultiSelect" filter.

    Tuesday, June 17, 2008 6:40 PM
  • User1024101778 posted

    Browse creates a query string populated with your search criteria and redirects to the page.  This is useful for users who would like to send links to people to see their view.  It also helps with creating a historical link in the back/forward navigator, although that will be less of an issue going forward in ASP.NET vNext with the feature (I forget the name).

    Tuesday, June 17, 2008 6:46 PM
  • User-853298616 posted

    Hhmmm... I've been testing my application and I just noticed that I get exceptions when the data entered is not in the required format.

    How can I validate the inputs?

    For example, if I insert some random text into a DateTime_Range field, I get the following exception: 

     The string was not recognized as a valid DateTime. There is a unknown word starting at index 0.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    
    Exception Details: System.FormatException: The string was not recognized as a valid DateTime. There is a unknown word starting at index 0.
    
    Source Error:
    
    Line 39:         {
    Line 40:             MethodInfo mi = typeof(Parameter).GetMethod("GetValue", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[] { typeof(object), typeof(string), typeof(TypeCode), typeof(bool), typeof(bool) }, null);
    Line 41:             return mi.Invoke(null, new object[] { value, defaultValue, type, convertEmptyStringToNull, ignoreNullableTypeChanges });
    Line 42:         }
    Line 43: 
    
    
    Source File: \DynamicData\DynamicExpressionParameterBase.cs    Line: 41 
    Isn't it possible to add some kind of code to validate the input before sending it to the filtering mechanism? Something like this (tried it and it doesn't work).



    Another problem: An exception gets thrown when filtering by a field that's a Nullable int: 
     Method 'Boolean Contains(System.String)' is not defined for type 'System.Nullable`1[System.Int32]'
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    
    Exception Details: System.ArgumentException: Method 'Boolean Contains(System.String)' is not defined for type 'System.Nullable`1[System.Int32]'
    
    Source Error:
    
    Line 82: 
    Line 83:             ParameterExpression parameterExpression = Expression.Parameter(itType, "");
    Line 84:             return Expression.Lambda
    Line 85:                         (
    Line 86:                             Expression.Call
    
    
    Source File: \DynamicData\LikeExpressionParameter.cs    Line: 84 
     
    Sunday, June 22, 2008 9:31 PM
  • User1024101778 posted

    For your first issue I suggest you add a Validation Control to the DateTime_Range user control in the DynamicData/FilterTempaltes folder, or do manual validation in the MinValue and MaxValue property getters.  The ValidationControls are the better way to handle this.  Take a look at the DatTime_Edit user control in DynamicData/FieldTempaltes for an example.

    For the second issue I do not believe that the Filtering controls support filtering for NULL values.  The reason is that filtering controls see NULL as no criteria provided.  I suggest creating a custom FilterTemplate which supports null values.  Here are a couple of links on examples on how to do this:

     http://blogs.catalystss.com/blogs/josh_heyse/archive/2008/04/11/a-richer-dynamicfilterrepeater-part-4-custom-dynamicfiltercontrols-amp-expressions.aspx

     http://blogs.catalystss.com/blogs/josh_heyse/archive/2008/05/23/a-richer-dynamicdatafilter-part-5-columncontains.aspx

     

    Tuesday, June 24, 2008 9:45 AM
  • User-853298616 posted

     I had already tried using a Validation Control, like I did here. Just did the same thing I had done for the DateTime_Edit FieldTemplate.

    Basically added a CustomValidator: 

    <asp:CustomValidator ID="CustomValidator1" runat="server" 
    	ErrorMessage="Data inicial inválida"
    	ControlToValidate="cMin" 
    	OnServerValidate="Validate_DateMin">
    </asp:CustomValidator>
     And a handler to perform the validation in the codebehind: 
    protected void Validate_DateMin(object source, ServerValidateEventArgs args)
            {
                System.DateTime tempDateTime;
                String textDateTime = cMin.Text;
                if (System.DateTime.TryParse(textDateTime, out tempDateTime))
                {
                    args.IsValid = true;
                }
                else
                {
                    args.IsValid = false;
                }
            }

    I confirmed that the Validator is working by placing a breakpoint inside the validation handler and checking that args.IsValid is set to false, so that's not where the problem comes from.

    Btw, this is one of those exceptions that only shows up in the browser if EnablePartialRendering is set to false.

    Tuesday, June 24, 2008 10:20 AM
  • User1024101778 posted

    If you set a break point at

    Line 40: return mi.Invoke(null, new object[] { value, defaultValue, type, convertEmptyStringToNull, ignoreNullableTypeChanges });


    What are the values for value, defaultValue & type?
     

     

    Tuesday, June 24, 2008 10:25 AM
  • User-853298616 posted

    If you set a break point at

    Line 40: return mi.Invoke(null, new object[] { value, defaultValue, type, convertEmptyStringToNull, ignoreNullableTypeChanges });


    What are the values for value, defaultValue & type? 

    value = "sdf" (the random string I put there)

    defaultvalue = null

    type = DateTime

    Tuesday, June 24, 2008 11:02 AM
  • User1024101778 posted

     The issue is that the DynamicFilterForm doesn't know to use that validator, before trying to searching.  If you use a client side regular expression validator instead, the form won't post back and you'll be ok.  I am going to be making a couple of change to the DynamicData filtering conrols tonight i'll see if I can add validator support in.

     
     

    Tuesday, June 24, 2008 11:26 AM
  • User-853298616 posted

     Oh, that was what I was afraid of...

    Yeah, some javascript on the client should do it, but I always have to keep in mind that the app should work in browsers with javascript disabled. That's why I want the validation on the server (regardless of it being done in the client as well) to avoid the users from getting exceptions in their face.

    I'm looking forward for your update. Hope to see the validator support built in.

    Thks.

    Tuesday, June 24, 2008 12:14 PM
  • User-853298616 posted

    I ended up implementing a workaround for this issue of not being able to validate de dates. Since I don't need to specify the day of the month (and so the leap years' problem doesn't apply), I transformed the control into 4 dropdownlists, 2 for the min date and 2 for the max date, and now I don't have to care about incorrect inputs.

    Thursday, June 26, 2008 6:26 PM
  • User-1776315162 posted

    This post is great and I think it'll be very useful to many developers.

    I find it really useful. Hope Dynamic data can add in this functionality.

    Thursday, July 17, 2008 11:15 PM
  • User-853298616 posted

     Hello,

     I'm having quite a struggle to display something that shoul be simple: the total row count.

    I've tried basically 2 things (suggested in a thread in the "Data Presentation Controls" forum):

     

    protected void GridDataSource_Selected(object sender, LinqDataSourceStatusEventArgs e)  
    {  
        totalLabel.Text = e.TotalRowCount.ToString();  
    }
    and 
    protected void LinqDataSource1_Selected(object sender, LinqDataSourceStatusEventArgs e)  
    {  
        System.Collections.Generic.List<country> lst  = e.Result as System.Collections.Generic.List<country>;  
        int count = lst.Count;  
    }</country></country>

    the first one returns -1 and the second returns the number of rows for the current page, and not the total.

    In another website (FYI, stackoverflow) I was directed to a page about the TotalRowCount Property. I made sure that all the values are set correctly. Autopage and AllowPaging are both set to true and RetrieveTotalRowCount is set to true (I don't know where to set this, but I checked it in debug mode). Also in debug mode I found out that arguments.TotalRowCount is set to the correct value. But somehow the value that comes out is not right. All this has made me think that this has something to do with using this custom DynamicLinqDataSource instead of the LinqDataSource, and that's why I'm posting in this thread.

    Any ideas on what might be the solution?

    Thanks in advance.

    Tuesday, August 26, 2008 11:11 AM
  • User1024101778 posted

    You have to set RetreiveTotalRowCount to true during the Selecting event on the DynamicLinqDataSource.


    protected void GridDataSource_Selecting(object sender, LinqDataSourceSelectEventArgs e)
    {
    e.Arguments.RetrieveTotalRowCount = true;
    }

     

     Then retrieve the TotalRowCount during the Selected event.


    protected void GridDataSource_Selected(object sender, LinqDataSourceStatusEventArgs e)
    {
    Response.Write(e.TotalRowCount.ToString());
    }

    I verified this still works with the DynamicLinqDataSource. 

    Tuesday, August 26, 2008 12:06 PM
  • User-853298616 posted

     Damn! So why doesn't it work for me? I just did exactly that, and I still get the -1 response.

    I noticed that both of those methods get called 3 times (and the value of TotalRowCount is always -1). Is this the expected behaviour?

    Tuesday, August 26, 2008 4:00 PM
  • User1024101778 posted

     Damn! So why doesn't it work for me? I just did exactly that, and I still get the -1 response.

    I noticed that both of those methods get called 3 times (and the value of TotalRowCount is always -1). Is this the expected behaviour?

     

     

    The method is executed twice for me, not 3 times, but I am looking into that.  What is your data source?   Does CanRetrieveTotalRowCount  == true?  http://msdn.microsoft.com/en-us/library/system.web.ui.datasourceselectarguments.retrievetotalrowcount.aspx

    Tuesday, August 26, 2008 4:10 PM
  • User-853298616 posted

     The data source is a DynamicLinqDataSource. 

    <cc1:dynamiclinqdatasource id="<span" class="st">"GridDataSource" runat="server" AutoPage="true"
                    EnableDelete="true" onselected="GridDataSource_Selected" 
                    onselecting="GridDataSource_Selecting">
                </cc1:dynamiclinqdatasource>
     

     CanRetrieveTotalRowCount is set to true. Checked its value in Debug mode, when accessing the List page, in the same place where the TotalRowCount is set (to the expected value, the one that doesn't show up on the page).

    Tuesday, August 26, 2008 6:02 PM
  • User-853298616 posted

    The method is executed twice for me, not 3 times, but I am looking into that.  What is your data source?   Does CanRetrieveTotalRowCount  == true?

    Do you have any more info on this? I still can't retrieve the correct value? Have you made any modifications to the code (in the last month or so) that might have changed the behaviour? Thks
    Saturday, September 6, 2008 10:28 AM
  • User-853298616 posted

     I'm trying to change the behaviour of the "Contains" filter. I need to change the query string so that the % wildcard substitutes any space and also appears in the begining and end of the query.

    So, when I insert "foo bar" into a "Contains" filter, instead of doing a SELECT... LIKE 'foo bar' (which is what I suppose it's being done), I need it to do a SELECT... LIKE '%foo%bar%'.

    Already tried to change the LikeExpressionParameter.cs file:

     

    if (Like == LikeType.StartsWith)
                    methodInfo = typeof(string).GetMethod("StartsWith", new Type[] { typeof(string) });
                else if (Like == LikeType.EndsWith)
                    methodInfo = typeof(string).GetMethod("EndsWith");
                else
                {
                    Value = Value.Replace(' ', '%');
                    Value = "%" + Value + "%";
                }

      without any luck (the Value variable gets its value changed, but that doesn't affect the result of the filtering).

    Thanks in advance.

    Wednesday, November 26, 2008 8:50 PM