Kentico 10过滤中继器,多个过滤器无法正常工作

时间:2017-11-06 23:10:13

标签: filter content-management-system repeater kentico

我有一个数据源,过滤器和过滤后的转发器,我为其创建了自定义过滤器。

出于某种原因,我的过滤器在屏幕上没有其他过滤器。一个可以正常使用屏幕上的其他过滤器。

当我在屏幕上有另一个过滤器时,最后一个过滤器拒绝工作,但没有任何其他工作正常。

我很确定它与我后面的文件后面的代码有关。

FILTER#1

"releaseCompileClasspath"

FILTER#2

using CMS.DocumentEngine;
using CMS.Helpers;
using System;
using System.Web;
using System.Web.UI.WebControls;
using CMS.DocumentEngine.Web.UI;

public partial class CMSGlobalFiles_SectorFilterControl : CMSAbstractDataFilterControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    /// <summary>
    /// Sets up the inner child controls.
    /// </summary>
    private void SetupControl()
    {
        // Hides the filter if StopProcessing is enabled
        if (this.StopProcessing)
        {
            this.Visible = false;
        }
        // Initializes only if the current request is NOT a postback
        else if (!RequestHelper.IsPostBack())
        {
            // Loads product departments as filtering options
            InitializeClientSectors();
        }
    }
    /// <summary>
    /// Loads all existing product departments as filtering options into the department drop-down list.
    /// </summary>
    private void InitializeClientSectors()
    {
        // Adds the default '(all)' option
        this.drpSector.Items.Insert(0, new ListItem("(all)", "##ALL##"));
        var clientSectors = DocumentHelper.GetDocuments("BBUS.Sector")
                                .Path("/Sector/", PathTypeEnum.Children)
                                .OnSite("Balfour-dev.allata.com");
        if (!DataHelper.DataSourceIsEmpty(clientSectors))
        {
            int count = 1;
            foreach (var clientSector in clientSectors)
            {
                var ClientSectorID = clientSector.GetValue("SectorID").ToString();
                this.drpSector.Items.Insert(count++, new ListItem(clientSector.DocumentName, ClientSectorID));
            }
        }
    }
    /// <summary>
    /// Generates a WHERE condition and ORDER BY clause based on the current filtering selection.
    /// </summary>
    private void SetFilter()
    {
        string where = null;
        // Generates a WHERE condition based on the selected product department
        if (this.drpSector.SelectedIndex > 0 && this.drpSector.SelectedValue != null)
        {
            //where = string.Format("clientSector = {0}", this.drpClientSector.SelectedValue);
            where = string.Format(
                "sector LIKE '%|{0}|%' " +
                "OR sector LIKE '{0}|%' " +
                "OR sector LIKE '%|{0}' " +
                "OR sector = '{0}'", this.drpSector.SelectedValue);
        }
        if (where != null)
        {
            // Sets the Where condition
            this.WhereCondition = where;
        }
        // Raises the filter changed event
        this.RaiseOnFilterChanged();
    }
    /// <summary>
    /// Init event handler.
    /// </summary>
    protected override void OnInit(EventArgs e)
    {
        // Creates the child controls
        SetupControl();
        base.OnInit(e);
    }
    /// <summary>
    /// PreRender event handler
    /// </summary>
    protected override void OnPreRender(EventArgs e)
    {
        var ClientSectorID = HttpContext.Current.Request.QueryString.Get("SectorID");
        // Checks if the current request is a postback
        if (RequestHelper.IsPostBack())
        {
            // Applies the filter to the displayed data
            SetFilter();
        }
        else if (!string.IsNullOrEmpty(ClientSectorID))
        {
            this.drpSector.SelectedIndex = this.drpSector.Items.IndexOf(this.drpSector.Items.FindByValue(ClientSectorID));
            SetFilter();
        }
        base.OnPreRender(e);
    }
    protected void btnFilter_Click(object sender, EventArgs e)
    {
        // Remove Query Strings
        string url = Request.RawUrl.Split(new[] { '?' })[0];
        // Add ClientSectorID Query String
        string updatedQueryString = "?" + "SectorID=" + this.drpSector.SelectedValue;
        Response.Redirect(url + updatedQueryString);
    }
}

1 个答案:

答案 0 :(得分:1)

可悲的是,这只是一个限制,每个转发器/数据源只能有1个过滤器(似乎除了智能搜索,它可以处理多个)。

您很可能需要将两个过滤器合并为一个过滤器,并将逻辑组合到一个条件中。

https://docs.kentico.com/k10/developing-websites/loading-and-displaying-data-on-websites/filtering-and-paging-data

虽然允许多个过滤器会很棒!