ASP.NET Gridview日期过滤器

时间:2016-10-08 19:44:56

标签: asp.net

 <asp:TextBox ID="TextBox1" runat="server" style="text-align: center; margin-left: 15px; margin-top: 16px" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>

<asp:Button ID="Button1" runat="server" Text="Search" Width="73px" Height="26px" OnClick="Button1_Click" />

<asp:GridView ID="GridView2" runat="server" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="GridView2_SelectedIndexChanged" Width="1322px" OnRowCommand="GridView2_RowCommand" Height="330px" style="text-align: center">

<asp:BoundField DataField="person_num" HeaderText="person_num" SortExpression="person_num" /
   <asp:BoundField DataField="creation_date" HeaderText="creation_date" SortExpression=creationn_date" />

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:bConnectionString %>" SelectCommand="SELECT dbo.UtcToLocal(creation_date), [action_id], [terminal_name], [ [person_num] FROM [TEST] WHERE  ([person_num] LIKE '%' + @person_num + '%' )  or ([creation_date] LIKE '%' + @creation_date + '%' )  ;" OnSelected="SqlDataSource1_Selected">
  <SelectParameters>
<asp:ControlParameter ControlID="TextBox1" Name="person_num" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="TextBox1" Name="creation_date" PropertyName="Text" Type="String" />

 </SelectParameters>
            </asp:SqlDataSource>

我想按date而不是datetime过滤我的数据。

1 个答案:

答案 0 :(得分:0)

使用以下SQL仅将日期部分与提供的日期进行比较

(CONVERT(VARCHAR(10), [creation_date] , 110)) >= @creation_date and CONVERT(VARCHAR(10), [creation_date] , 110)) <= @creation_date)