我正在尝试使用带有两个文本框的 AjaxToolKit CalendarExtender 控件来开发搜索过滤器。第一个文本框用于(开始日期),第二个文本框用于结束日期,单击(搜索)按钮后,结果应显示在 ListView 中,并在 ListView 的第一列添加一个复选框。
仅供参考,数据库设计如下:
Employee Table: Username, Name...
SuggestionsLog: ID, Title, Description, DateSubmitted, StatusID
SuggestionsStatus: ID, Status
(DateSubmitted 是一个日期时间数据类型字段)
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>
代码隐藏:
protected void searchButton_Click(object sender, EventArgs e)
{
string connString = ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(connString);
string cmd = @"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)";
SqlDataAdapter sda = new SqlDataAdapter(cmd,conn);
sda.SelectCommand.Parameters.AddWithValue("@startDate", txtStartDate.Text);
sda.SelectCommand.Parameters.AddWithValue("@finishDate", txtEndDate.Text);
DataSet ds = new DataSet();
sda.Fill(ds, "table");
FilteredSuggestions.DataSource = ds.Tables["table"];
FilteredSuggestions.DataBind();
}