/// <summary> /// Applies filter. /// </summary> /// <param name="searchCondition">Search condition</param> /// <param name="searchSort">Search sort</param> public void ApplyFilter(string searchCondition, string searchSort) { // Call Result webpart id ISearchFilterable resultWebpart = (ISearchFilterable)CMSControlsHelper.GetFilter(ResultWebpartID); if (resultWebpart != null) { resultWebpart.ApplyFilter(searchCondition, searchSort); } }
/// <summary> /// Page load. /// </summary> protected void Page_Load(object sender, EventArgs e) { if (StopProcessing) { // Do nothing } else { if (!RequestHelper.IsPostBack() && (FilterMode != SearchFilterModeEnum.TextBox)) { // If query name filled - execute it if (!string.IsNullOrEmpty(FilterQueryName)) { // Execute query DataSet ds = ConnectionHelper.ExecuteQuery(FilterQueryName, null, FilterWhere, FilterOrderBy); if (!DataHelper.DataSourceIsEmpty(ds)) { // Check that dataset has at least 3 columns if (ds.Tables[0].Columns.Count < 3) { lblError.ResourceString = "srch.filter.fewcolumns"; lblError.Visible = true; return; } // Loop thru all rows foreach (DataRow dr in ds.Tables[0].Rows) { AddItem(dr[0].ToString(), dr[1].ToString(), ResHelper.LocalizeString(dr[2].ToString())); } } } // Else if values are filled - parse them else if (!string.IsNullOrEmpty(FilterValues)) { // Split values into rows string[] rows = FilterValues.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); // Loop thru each row foreach (string row in rows) { string trimmedRow = row.Trim().TrimEnd('\r'); if (!string.IsNullOrEmpty(trimmedRow)) { string[] values = trimmedRow.Split(';'); if (values.Length == 3) { AddItem(values[0], values[1], values[2]); } else { lblError.ResourceString = "srch.filter.badformat"; lblError.Visible = true; return; } } } } } // Get webpart ID string webpartID = ValidationHelper.GetString(GetValue("WebpartControlID"), ClientID); // Try to get selected values from querystring - but only if is not postback if (!RequestHelper.IsPostBack()) { string selectedItems = QueryHelper.GetString(webpartID, ""); // If none of items are selected - try to get default values if (string.IsNullOrEmpty(selectedItems)) { selectedItems = DefaultSelectedIndex; } if (!string.IsNullOrEmpty(selectedItems)) { string[] splittedItems = selectedItems.Split(';'); foreach (string item in splittedItems) { switch (FilterMode) { case SearchFilterModeEnum.Checkbox: SelectItem(item, chklstFilter); break; case SearchFilterModeEnum.RadioButton: SelectItem(item, radlstFilter); break; case SearchFilterModeEnum.DropdownList: SelectItem(item, drpFilter); break; default: txtFilter.Text = item; break; } } } } string applyFilter = ""; string ids = ""; // Set up controls switch (FilterMode) { // Set text box case SearchFilterModeEnum.TextBox: txtFilter.Visible = true; txtFilter.WatermarkCssClass = WatermarkCssClass; txtFilter.WatermarkText = WatermarkText; txtFilter.AutoPostBack = FilterAutoPostback; if (!String.IsNullOrEmpty(DefaultSelectedIndex) && String.IsNullOrEmpty(txtFilter.Text) && !URLHelper.IsPostback()) { txtFilter.Text = DefaultSelectedIndex; } // Apply filter only of textbox contains something if (!String.IsNullOrEmpty(txtFilter.Text)) { // Prepare right condition when filter values aren't empty if (!String.IsNullOrEmpty(FilterValues)) { string[] rows = FilterValues.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); // Loop thru each row foreach (string row in rows) { string trimmedRow = row.Trim(); if (!string.IsNullOrEmpty(trimmedRow)) { applyFilter += trimmedRow + ":(" + SearchHelper.ProcessSearchKeywords(txtFilter.Text, SearchOptionsEnum.NoneSearch) + ") "; } } } else { applyFilter = txtFilter.Text; } } ids = HttpUtility.UrlEncode(txtFilter.Text); break; // Set checkbox list case SearchFilterModeEnum.Checkbox: // Set visibility and layout chklstFilter.Visible = true; chklstFilter.RepeatDirection = RepeatDirection.Vertical; if (FilterLayout == ControlLayoutEnum.Horizontal) { chklstFilter.RepeatDirection = RepeatDirection.Horizontal; } chklstFilter.RepeatLayout = GetLayoutEnumFromString(RepeatLayout); chklstFilter.RepeatColumns = this.RepeatColumns; // Get selected items applyFilter = GetSelectedItems(chklstFilter, out ids); // Set autopostback if (FilterAutoPostback) { chklstFilter.AutoPostBack = true; } break; // Set radio list case SearchFilterModeEnum.RadioButton: // Set visibility and layout radlstFilter.Visible = true; radlstFilter.RepeatDirection = RepeatDirection.Vertical; if (FilterLayout == ControlLayoutEnum.Horizontal) { radlstFilter.RepeatDirection = RepeatDirection.Horizontal; } radlstFilter.RepeatLayout = GetLayoutEnumFromString(RepeatLayout); radlstFilter.RepeatColumns = this.RepeatColumns; // Get selected items applyFilter = GetSelectedItems(radlstFilter, out ids); // Set autopostback if (FilterAutoPostback) { radlstFilter.AutoPostBack = true; } break; // Set dropdown list default: // Set visibility drpFilter.Visible = true; // Get selected items applyFilter = GetSelectedItems(drpFilter, out ids); // Set autopostback if (FilterAutoPostback) { drpFilter.AutoPostBack = true; } lblFilter.AssociatedControlID = drpFilter.ID; break; } // Apply filter and add selected values to querystring ISearchFilterable searchWebpart = (ISearchFilterable)CMSControlsHelper.GetFilter(SearchWebpartID); if (searchWebpart != null) { if (FilterIsConditional) { // If filter fieldname or value is filled if (!string.IsNullOrEmpty(applyFilter) && (applyFilter.Trim() != ":")) { // Handle filter clause if (!string.IsNullOrEmpty(FilterClause)) { applyFilter = FilterClause + "( " + applyFilter + " )"; } searchWebpart.ApplyFilter(applyFilter, null); } searchWebpart.AddFilterOptionsToUrl(webpartID, ids); } else { searchWebpart.ApplyFilter(null, applyFilter); searchWebpart.AddFilterOptionsToUrl(webpartID, ids); } } } }