我有一个asp.net c#网站我正在使用Visual Web Developer Express Edition 2010开发。在这个网站上我有一个FilterExpression应该过滤三个标准:开始日期,结束日期和关键字搜索。
我能够自己开始和结束日期过滤器,并且关键字搜索本身也可以工作。我遇到的麻烦就是让所有三个人一起工作。
我正在使用的代码(如下所示)默认显示所有记录(好),并在尝试过滤时执行以下操作:
这是我现在的代码,它试图整合所有三个但不起作用。任何建议都会有所帮助:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:sermonConnectionString %>"
SelectCommand="SELECT ID, sermon_date, sermon_speakerfirst + ' ' + sermon_speakerlast AS Speaker, sermon_title, sermon_subtitle, sermon_notes FROM what ORDER BY sermon_date DESC"
FilterExpression="([sermon_title] LIKE '%{0}%') AND ([sermon_date] >= '{1}' AND [sermon_date] <= '{2}')">
<FilterParameters>
<asp:ControlParameter ControlID="TextBox2" PropertyName="Text" Type="DateTime" ConvertEmptyStringToNull="true" />
<asp:ControlParameter ControlID="TextBox3" PropertyName="Text" Type="DateTime" ConvertEmptyStringToNull="true"/>
<asp:ControlParameter ControlID="SermonSearch" PropertyName="Text" Type="String"/>
</FilterParameters>
</asp:SqlDataSource>
答案 0 :(得分:0)
我只是想通过将日期/时间过滤器和关键字过滤器分成两个可搜索的区域来指出我已“解决”了这个问题。由于记录集不是那么大,因此没有真正的理由能够在此特定实例中按日期和关键字进行过滤。
答案 1 :(得分:0)
请参阅示例以获取包含日期范围过滤器的动态内容列表
public virtual IQueryable<DynamicContent> GetBusinessItemsByExpiryDate(DateTime theDate, int thisPageNo, ref int? totalCount)
{
//ToDo: Use FilterExperssion for filtering rather than above;
int? itemsToSkip = 0;
int? itemsPerPage = ItemsPerPageCount;
string towncity = string.Empty; string strSectorID = string.Empty;
//Guid sectorID;
if (pageNo > 0)
{
itemsToSkip = itemsPerPage * (pageNo - 1);
}
DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
Type businessItemType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Businesslisting.BusinessItem");
var query = dynamicModuleManager.GetDataItems(businessItemType);
System.Globalization.CultureInfo culture = null;
culture = System.Globalization.CultureInfo.CurrentUICulture;
FilterExpression = ContentHelper.AdaptMultilingualFilterExpressionRaw(FilterExpression, culture);
string filterExpression = DefinitionsHelper.GetFilterExpression(FilterExpression, AdditionalFilter);
filterExpression += "Visible = true AND Status = Live";
if (theDate != DateTime.MinValue)
{
filterExpression += string.Format(" And ExpiryDate >= ({0}) AND ExpiryDate <= ({1})", theDate.AddDays(-14).ToString("yyyy/MM/dd"), theDate.AddDays(42).ToString("yyyy/MM/dd"));
}
SortExpression += "Title";
query = DataProviderBase.SetExpressions<DynamicContent>(query, filterExpression, SortExpression, itemsToSkip, new int?(itemsPerPage ?? 0), ref totalCount);
TotalItemCount = (int)totalCount;
return query;
}