1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How to programmatically set a filter

How to programmatically set a filter

6 posts, 0 answered
  1. Michael Park
    Michael Park avatar
    13 posts
    Registered:
    23 Oct 2009
    19 Nov 2009
    Link to this post
    I need to filter my events and news by a tag based on the theme set on the page.  I've set up tags that match the names of the themes I've set up.  How would I go about doing this?

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    19 Nov 2009
    Link to this post
    Hello Michael Park,

    You have to create a custom control that inherits from EventsView. Override CreateChildControls and create a new instance of ContentFilterBuilder and filter the list.

    sample:

    protected override void CreateChildControls()
       {
           base.CreateChildControls();
     
     
           string tagName= Page.Request.Url.PathAndQuery + "?CustomTag";
           
     
           if (this.Page != null && this.Page.Request.QueryString["CustomTag"] != null)
           {
               ContentFilterBuilder filterBuilder = new ContentFilterBuilder(this);
               filterBuilder.AddFilter(new ContentFilterStatement("Tag.Name", Page.Request.QueryString["CustomTag"].ToString(),
                                                                                    ContentFilter.Condition.In,
                                                                                 ContentFilter.JoinType.And));
           }
       }


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Michael Park
    Michael Park avatar
    13 posts
    Registered:
    23 Oct 2009
    19 Nov 2009
    Link to this post
    Once I create the custom control how would I map it to be used by a presentation mode?  I see how to update the mastertemplatepath but don't necessarily see how to map the codebehind or class to use.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    19 Nov 2009
    Link to this post
    Hello Michael Park,

    There are two options

    1. Override SingleItemTemplatePath and ItemListTemplatePath properties and return the path to your template.
    2. Create a control designer for your custom control and template for the control designer from where you can witch the presentation modes.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Michael Park
    Michael Park avatar
    13 posts
    Registered:
    23 Oct 2009
    19 Nov 2009
    Link to this post
    Can you give more detail on this reply?  I see how to override the template path and I can set that to my ascx user control, but then my user control can't inherit from EventsView since EventsView is not derived from usercontrol.  I only see a place to map event to ascx templatepaths in the eventsviewcontroldesigner.ascx
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    19 Nov 2009
    Link to this post
    Hi Michael Park,

    As I see it no where in this there is mentioned something about a user control. You need to create a custom class that should inherits from EventsView.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
6 posts, 0 answered