I built some custom filtering controls for a specific page type and I created an alternative form to include the custom controls. The filtering works perfectly fine. The only issue I have is the 'Reset' button does not reset the controls. How do I handle the reset on each custom control?
All the custom controls have a similar implementation. Below is the code for one of the custom filtering controls.
public partial class CMSModules_Custom_Filters_PageTagsFilter : FormEngineUserControl
{
/// <summary>
/// Gets or sets the value selected within the filter.
/// </summary>
public override object Value
{
get
{
return chkPageTags.GetSelectedItems();
}
set
{
//chklFeedTypes.SelectedValue = ValidationHelper.GetString(value, "");
}
}
/// <summary>
/// Generates the SQL Where condition used to limit the data displayed in the connected UniGrid.
/// </summary>
public override string GetWhereCondition()
{
string whereQuery = string.Empty;
if (Value != null)
{
var allValues = (IEnumerable<ListItem>)Value;
List<ListItem> items = allValues.ToList();
if (items.Count > 0)
{
whereQuery = "(";
for (int i = 0; i < items.Count; i++)
{
if (whereQuery != "(")
{
whereQuery += " OR ";
}
// Add a condition for each value
whereQuery += "EXISTS (SELECT 1 FROM STRING_SPLIT(PageTags, ';') WHERE RTRIM(LTRIM(value)) = N'" + items[i].Value + "')";
}
whereQuery += ")";
}
}
return whereQuery;
}
/// <summary>
/// Loads the filtering options during the initialization of the control.
/// </summary>
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
ITagGroupInfoProvider tagGroupProvider = new TagGroupInfoProvider();
var tagGroup = tagGroupProvider.Get().Where(o => o.TagGroupName == "ContentHub").FirstOrDefault();
if(tagGroup != null)
{
int groupId = tagGroup.TagGroupID;
ITagInfoProvider provider = new TagInfoProvider();
var tags = provider.Get().Where(o=>o.TagGroupID == groupId);
var allTags = tags;
chkPageTags.DataSource = allTags;
chkPageTags.DataBind();
}
}
}
<%@ Control Language="C#" AutoEventWireup="true" Codebehind="PageTagsFilter.ascx.cs"
Inherits="CMSModules_Custom_Filters_PageTagsFilter" %>
<%@ Register namespace="CMS.Base.Web.UI" assembly="CMS.Base.Web.UI" tagPrefix="cms" %>
<div style="max-height:200px;max-width:300px;overflow-y: scroll;">
<cms:CMSCheckBoxList ID="chkPageTags" runat="server" DataValueField="TagID" DataTextField="TagName">
</cms:CMSCheckBoxList>
</div>