开发者

FilterExpression problem - multiple conditions

I have an asp.net c# website I'm developing with Visual Web Developer Express Edition 2010. In this website I have a FilterExpression that should filter three criteria: a start date, end date, and keyword search.

I am able to get the start and end date filter working by itself, and also the keyword search is working by itself. What I'm having trouble with is getting all three to work together.

The code I'm using (below) displays all records by default (good) and does the following when trying to filter:

  • search keyword: all records
  • search keyword plus date range: no records
  • just date range: all records

Here's the code I have now, which tries to integrate all three but does not work. Any advice would be helpful:

<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:ControlPar开发者_如何学运维ameter ControlID="SermonSearch" PropertyName="Text" Type="String"/>
</FilterParameters>
</asp:SqlDataSource>


Just thought I'd point out that I 'solved' this issue by breaking out the date/time filters and keyword filters into two searchable areas. Since the record set isn't that large there's no real reason to be able to filter by date AND keyword in this specific instance.


Please see a sample to get Dynamic content list with date range filters

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;
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜