Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > How do you get a custom filter to actually work? View modes: 
User avatar
Member
Member
Darren-DesignReligion.co - 2/2/2010 10:20:37 AM
   
How do you get a custom filter to actually work?
Hi all,

Perhaps a noob question, though i will ask anyway :-)

I have a Datalist displaying custom documents; all working well.

I am trying to apply a custom filter to this to simply filter the results of documents though cannot either find a good example (before anybody posts the link, i have read http://www.kentico.com/docs/devguide/index.html?using_datasource_web_parts.htm and it didn't help...)

This is what i have tried:

Created a new module, based on the ProductFilter.ascx, and stripped out everything i don't need -- all i have is a single drop down list "Music Category" with 3 options in it.

I have added the General->Filter to my page and given both a filter name and location to my module.

no matter what i try, i can't get the datalist to perform the actual filter....

here is my module filter: (i have tinkered with the FilterName and FilterByQuery properties but to no avail -- might only be these i have wrong? )


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CMS.GlobalHelper;
using CMS.CMSHelper;
using CMS.PortalControls;
using CMS.Controls;

public partial class CMSWebParts_MyWebParts_MusicCategoryFilter: CMSAbstractBaseFilterControl
{
#region "Properties"


#endregion

public bool FilterByQuery = true;
public string FilterName = "CategoryMusicFilter";

protected void Page_Load(object sender, EventArgs e)
{
Response.Write("XX");

if (!RequestHelper.IsPostBack())
{
if (this.FilterByQuery)
{
// Get filter setings from query
GetFilter();
}
}

// Set filter settings
SetFilter();
}


protected void btnFilter_Click(object sender, EventArgs e)
{
if (this.FilterByQuery)
{
// Handle all query parameters
string url = UrlHelper.RawUrl;

url = UrlHelper.RemoveParameterFromUrl(url, "cat");
if (CategoryList.SelectedValue != "")
{
url = UrlHelper.AddParameterToUrl(url, "cat", CategoryList.SelectedValue);
}


// Redirect with new query parameters
UrlHelper.Redirect(url);
}
else
{
// Set filter settings
SetFilter();
}
}


private void SetFilter()
{
string where = "";

// Build where condition according to dropdowns setings
if (CategoryList.SelectedValue != "")
{
where += "Category = '" + CategoryList.SelectedValue + "' ";
}

Response.Write("Where: " + where);
if (where != "")
{
// Set where condition
this.WhereCondition = where;
}


// Filter changed event
this.RaiseOnFilterChanged();
}


private void GetFilter()
{

string cat = QueryHelper.GetString("cat", "");

// Set order if in query
if (cat != "")
{
try
{
CategoryList.SelectedValue = cat.ToString();
}
catch { }
}
}
}




does anybody have step by step to creating a simple filter that is to be used with a datalist?

Cheers in advance..













User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 2/17/2010 5:03:59 AM
   
RE:How do you get a custom filter to actually work?
Hello,

I have tested your code and it works correctly.

1. Did you configure the name of filter in the data source web part properties?

2. Do you use the Basic datalist web part for displaying?

3. Do you see the controls of your filter on the page? Has the URL the correct query string (cat)?

Thank you in advance for your reply.


Best regards,
Helena Grulichova