【问题标题】:How can I get a filter to work with an Event Calendar webpart?如何让过滤器与事件日历 web 部件一起使用?
【发布时间】:2012-05-17 23:15:48
【问题描述】:

我创建了一个自定义事件文档,它扩展了普通事件文档的字段。我添加了一个字段,可以在管道分隔列表中保留 0 到多个类别 ID。类别存储在自定义表中。

这是我的过滤代码:

public partial class CMSGlobalFiles_EventCategoryFilter : CMSAbstractDataFilterControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected override void OnInit(EventArgs e)
    {
         SetupControl();

        base.OnInit(e);
    }

    protected override void OnPreRender(EventArgs e)
    {
        if (RequestHelper.IsPostBack())
        {
            setFilter();
         }

        base.OnPreRender(e);
    }

    private void SetupControl()
    {
        if (this.StopProcessing)
        {
            this.Visible = false;
        }

        else if (!RequestHelper.IsPostBack())
        {
            InitializeCategory();
        }

    }

    private void InitializeCategory()
    {
        CustomTableItemProvider customTableProvider = ne CustomTableItemProvider(CMSContext.CurrentUser);

        string where = "";

        string tableName = "customtable.EventCategory";

        DataClassInfo customTable = DataClassInfoProvider.GetDataClass(tableName);

        if (customTable != null)
        {

            DataSet dataSet = customTableProvider.GetItems(tableName, where, null);

            if (!DataHelper.DataSourceIsEmpty(dataSet))
            {
                this.drpCategory.DataSource = dataSet;
                this.drpCategory.DataTextField = "CategoryName";
                this.drpCategory.DataValueField = "ItemGUID";

                this.drpCategory.DataBind();

                this.drpCategory.Items.Insert(0, new ListItem("(all)", "##ALL##"));
            }
        }

    } 

    private void setFilter() 
    {
        string where = null;

        if (this.drpCategory.SelectedValue != null)
        {
            Guid itemGUID = ValidationHelper.GetGuid(this.drpCategory.SelectedValue, Guid.Empty );

            if (itemGUID != Guid.Empty)
            {
                where = "EventCategory LIKE \'%" + itemGUID.ToString() + "%\'";
            }

         }

         if (where != null)
         {
             this.WhereCondition = where;
         }

         this.RaiseOnFilterChanged();
     }

}

这个过滤器在使用基本的转发器和文档数据源时效果很好。当我使用事件日历时,它没有。我正在使用 Kentico 版本 6.0.30

【问题讨论】:

    标签: kentico


    【解决方案1】:

    问题在于 EventCalendar 的不同生命周期,基于基于标准 .Net 日历的 CMSCalendar 控件。

    首先,我们的开发人员发现了一种解决此问题的方法,并允许您的场景默认运行。此修复程序将包含在 6.0.33 修补程序中(计划于 25 日星期五发布)。 对于给您带来的不便,我深表歉意。

    除了即将到来的修复之外,还可以通过修改(克隆)Web 部件、将过滤器控件直接集成到该 Web 部件中并在 DataBind 之前在 OnPreRender 中设置日历的 Where 条件来使 EventCalendar 过滤其结果作为

    protected override void OnPreRender(EventArgs e)
    {
        calItems.WhereCondition = "some filtering condition";
        ...
    

    如果您可以修复您的 CMS 实例,那肯定会更省力。

    问候,

    Zdenek / Kentico 支持

    【讨论】:

      猜你喜欢
      • 2020-09-08
      • 2018-03-04
      • 2014-06-29
      • 1970-01-01
      • 2015-02-14
      • 1970-01-01
      • 2017-05-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多