过滤gridview日期之间不会获取Date To的记录

时间:2013-03-29 16:23:55

标签: asp.net

我正在尝试过滤gridview以显示特定日期之间的订单。我设法让它工作,但它没有显示Date To的记录。它只显示那些日期之间。日期中存在的记录显示...

 <asp:EntityDataSource ID="EDS_Orders" runat="server" EnableUpdate="true" EnableFlattening="False"  OrderBy="it.Order_date ASC"
                      ConnectionString="name=Bohemian1Entities" DefaultContainerName="Bohemian1Entities" EntitySetName="t_customer_orders"
                      Where="it.UserName is not null and (it.Order_date Between @DateFrom AND @DateTo) AND (it.UserName Like '%' + @UserName +  '%') " >
    <WhereParameters>                                                     

         <asp:ControlParameter ControlID="ddlDateFrom" Name="DateFrom" 
         Type="DateTime" DefaultValue="%"/>
         <asp:ControlParameter ControlID="ddlDateTo" Name="DateTo" 
         Type="DateTime" DefaultValue="%"/>
         <asp:ControlParameter ControlID="ddlCustomers" Name="UserName" PropertyName="Text" 
         Type="String" DefaultValue="%"/>

    </WhereParameters>

</asp:EntityDataSource>

1 个答案:

答案 0 :(得分:0)

尝试重写Where子句,如下所示:

Where="it.UserName is not null and (CAST(it.Order_date AS DATE) Between @DateFrom AND @DateTo) 
    AND (it.UserName Like '%' + @UserName + '%')"