C# 如何根据ListView中的两个日期显示搜索结果?
我试图使用AjaxToolKit CalendarExtender控件和两个文本框来开发搜索过滤器。第一个文本框用于(开始日期),第二个文本框用于完成日期,单击(搜索)按钮后,结果应显示在列表视图中,并在列表视图的第一列添加复选框 供参考,数据库设计如下:C# 如何根据ListView中的两个日期显示搜索结果?,c#,asp.net,sql,sql-server-2008-r2,C#,Asp.net,Sql,Sql Server 2008 R2,我试图使用AjaxToolKit CalendarExtender控件和两个文本框来开发搜索过滤器。第一个文本框用于(开始日期),第二个文本框用于完成日期,单击(搜索)按钮后,结果应显示在列表视图中,并在列表视图的第一列添加复选框 供参考,数据库设计如下: Employee Table: Username, Name... SuggestionsLog: ID, Title, Description, DateSubmitted, StatusID SuggestionsStatus: ID,
Employee Table: Username, Name...
SuggestionsLog: ID, Title, Description, DateSubmitted, StatusID
SuggestionsStatus: ID, Status
(DateSubmitted是datetime数据类型字段)
StartDate和EndDate将基于数据库SuggestionsLog表中的DateSubmitted列问题在于从Ajax CalendarExtender中选择的日期格式为(2012年7月2日)。此外,我还编写了以下查询:
SELECT dbo.SafetySuggestionsLog.Title, dbo.SafetySuggestionsLog.Description, dbo.SafetySuggestionsLog.Username, dbo.SafetySuggestionsLog.DateSubmitted,
dbo.SafetySuggestionsStatus.Status
FROM dbo.SafetySuggestionsLog INNER JOIN
dbo.SafetySuggestionsStatus ON dbo.SafetySuggestionsLog.StatusID = dbo.SafetySuggestionsStatus.ID
WHERE (dbo.SafetySuggestionsLog.DateSubmitted = @startDate) AND (dbo.SafetySuggestionsLog.DateSubmitted = @finishDate)
我想在ListView中显示结果,但是,ListView上没有显示任何内容,我不知道为什么你能帮我一下吗?
ASP.NET:
<div>
<asp:Label ID="Label2" runat="server" Text="From: " />
<asp:TextBox ID="txtStartDate" runat="server" />
<asp:CalendarExtender ID="CalendarExtender1" runat="server" Enabled="True"
Format="MMMM d, yyyy" TargetControlID="txtStartDate">
</asp:CalendarExtender>
<asp:Label ID="Label3" runat="server" Text="To: " />
<asp:TextBox ID="txtEndDate" runat="server" />
<asp:CalendarExtender ID="CalendarExtender2" runat="server" Enabled="True"
Format="MMMM d, yyyy" TargetControlID="txtEndDate">
</asp:CalendarExtender>
<asp:Button ID="searchButton" runat="server" Text="Search"
onclick="searchButton_Click" />
<asp:ListView ID="FilteredSuggestions" runat="server"></asp:ListView>
</div>
试试这个:
使用BETWEEN指定日期范围
SELECT dbo.SafetySuggestionsLog.Title, dbo.SafetySuggestionsLog.Description, dbo.SafetySuggestionsLog.Username, dbo.SafetySuggestionsLog.DateSubmitted,
dbo.SafetySuggestionsStatus.Status
FROM dbo.SafetySuggestionsLog INNER JOIN
dbo.SafetySuggestionsStatus ON dbo.SafetySuggestionsLog.StatusID = dbo.SafetySuggestionsStatus.ID
WHERE (dbo.SafetySuggestionsLog.DateSubmitted Between @startDate AND @finishDate)
在一天开始的午夜之间: 因此,它将有效地排除@finishDate。如果您使用的是'Between'运算符,请注意这一点。如果这不是您想要的,请在建立时间窗口时使用
“,=”
运算符
WHERE (NOT((finishDate <= @startDate) OR (startDate > @finishDate)))
其中(不是((finishDate@finishDate)))
谢谢您的帮助。我真的很感激。
WHERE (NOT((finishDate <= @startDate) OR (startDate > @finishDate)))