diff --git a/knowledge-base/grid-filter-with-dynamically-created-filter-expressions.md b/knowledge-base/grid-filter-with-dynamically-created-filter-expressions.md new file mode 100644 index 000000000..9968e7773 --- /dev/null +++ b/knowledge-base/grid-filter-with-dynamically-created-filter-expressions.md @@ -0,0 +1,106 @@ +--- +title: Filter with dynamically created filter expressions +description: This article provides instructions on how to filter with dynamically created filter expressions +type: how-to +page_title: Filter with dynamically created filter expressions. | RadGrid +slug: grid-filter-with-dynamically-created-filter-expressions +tags: radgrid, filtering, buttons, rows +res_type: kb +--- + +## Environment + + + + + + + + +
ProductTelerik WebForms Grid for ASP.NET AJAX
+ +## Description + +I want to implement buttons to filter rows in a step-by-step process. The process involves listing and filtering rows in a Grid based on specific intervals. + +## Solution + +To achieve the desired behavior, you can follow these steps: + +1. Add a Filter control with the `Visible` property set to **false** to your page. +2. Create buttons in the header (or wherever you want) of a GridTemplateColumn in your RadGrid to trigger the filtering. +3. Handle the button click events and programmatically create filter expressions based on the given conditions. +4. Apply the filter expressions to the Grid and remove them after filtering is done. + +Here's a sample implementation for the first scenario using buttons in the header of a GridTemplateColumn: + +````ASP.NET + + + + + + + + + + + + + + + + +```` + +In the code-behind file, handle the button click events and create the filter expressions: + +````C# +protected void Step1Button_Click(object sender, EventArgs e) +{ + RadFilterGreaterThanOrEqualToFilterExpression expr1 = new RadFilterGreaterThanOrEqualToFilterExpression("OrderID"); + expr1.Value = 1; + RadFilter1.RootGroup.AddExpression(expr1); + + RadFilterGroupExpression group1 = new RadFilterGroupExpression(); + group1.GroupOperation = RadFilterGroupOperation.And; + + RadFilterLessThanOrEqualToFilterExpression expr2 = new RadFilterLessThanOrEqualToFilterExpression("OrderID"); + expr2.Value = 61; + RadFilter1.RootGroup.AddExpression(expr2); + + RadFilter1.FireApplyCommand(); + + RadFilter1.RootGroup.Expressions.Remove(expr1); + RadFilter1.RootGroup.Expressions.Remove(expr2); +} + +protected void Step2Button_Click(object sender, EventArgs e) +{ + RadFilterGreaterThanOrEqualToFilterExpression expr1 = new RadFilterGreaterThanOrEqualToFilterExpression("OrderID"); + expr1.Value = 61; + RadFilter1.RootGroup.AddExpression(expr1); + + RadFilterGroupExpression group1 = new RadFilterGroupExpression(); + group1.GroupOperation = RadFilterGroupOperation.And; + + RadFilterLessThanOrEqualToFilterExpression expr2 = new RadFilterLessThanOrEqualToFilterExpression("OrderID"); + expr2.Value = 150; + RadFilter1.RootGroup.AddExpression(expr2); + + RadFilter1.FireApplyCommand(); + + RadFilter1.RootGroup.Expressions.Remove(expr1); + RadFilter1.RootGroup.Expressions.Remove(expr2); +} +```` + +This implementation allows you to filter the Grid based on the given conditions by clicking the corresponding buttons in the header. + +Remember to adjust the column and filter expressions based on your specific requirements. + +## See Also + +- [Working with Expressions]({%slug filter/filter-expressions/working-with-expressions%}) + +