RadFilter exposes the ExpressionItemCreated event which is fired after each item creation.It provides a more easy and intuitive way of accessing the filter expression items. Depending on expressionthat was created the item in the arguments could be either RadFilterSingleExpressionItem or RadFilterGroupExpression.
Below is a sample code implementation which demonstrates how you can manipulate the filter items. The code logic forbids the creation of sub-group expressions by hiding the AddGroupExpressionButton and populates the RadFilterDropDownEditor with data.
publicDataTableGetDataTable(string query){String ConnString = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;SqlConnection conn =newSqlConnection(ConnString);SqlDataAdapter adapter =newSqlDataAdapter();
adapter.SelectCommand =newSqlCommand(query, conn);DataTable myDataTable =newDataTable();
conn.Open();try{
adapter.Fill(myDataTable);}finally{
conn.Close();}return myDataTable;}protectedvoidRadFilter1_ExpressionItemCreated(object sender,RadFilterExpressionItemCreatedEventArgs e){// Populate the RadDropDownList control for every ShipCountry field editorRadFilterSingleExpressionItem singleItem = e.Item asRadFilterSingleExpressionItem;if(singleItem !=null&& singleItem.FieldName =="ShipCountry"&& singleItem.IsSingleValue){RadDropDownList dropDownList = singleItem.InputControl asRadDropDownList;
dropDownList.DataSource =GetDataTable("SELECT DISTINCT ShipCountry FROM Orders");
dropDownList.DataBind();}// Removes the AddGroupExpressionButton for group expression other than the root groupRadFilterGroupExpressionItem groupItem = e.Item asRadFilterGroupExpressionItem;if(groupItem !=null){if(groupItem.IsRootGroup) groupItem.RemoveButton.Visible =false;else groupItem.AddGroupExpressionButton.Visible =false;}}
VB.NET
PublicFunction GetDataTable(query AsString)As DataTable
Dim ConnString As [String] = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString
Dim conn AsNew SqlConnection(ConnString)Dim adapter AsNew SqlDataAdapter()
adapter.SelectCommand =New SqlCommand(query, conn)Dim myDataTable AsNew DataTable()
conn.Open()Try
adapter.Fill(myDataTable)Finally
conn.Close()EndTryReturn myDataTable
EndFunctionProtectedSub RadFilter1_ExpressionItemCreated(sender AsObject, e As RadFilterExpressionItemCreatedEventArgs)Handles RadFilter1.ExpressionItemCreated
' Populate the RadDropDownList control for every ShipCountry field editorDim singleItem As RadFilterSingleExpressionItem =TryCast(e.Item, RadFilterSingleExpressionItem)If singleItem IsNotNothingAndAlso singleItem.FieldName ="ShipCountry"AndAlso singleItem.IsSingleValue ThenDim dropDownList As RadDropDownList =TryCast(singleItem.InputControl, RadDropDownList)
dropDownList.DataSource = GetDataTable("SELECT DISTINCT ShipCountry FROM Orders")
dropDownList.DataBind()EndIf' Removes the AddGroupExpressionButton for group expression other than the root groupDim groupItem As RadFilterGroupExpressionItem =TryCast(e.Item, RadFilterGroupExpressionItem)If groupItem IsNotNothingThenIf groupItem.IsRootGroup Then
groupItem.RemoveButton.Visible =FalseElse
groupItem.AddGroupExpressionButton.Visible =FalseEndIfEndIfEndSub
In the tables below are listed the properties of the expression items according to the type.
Gets the container holding the links menu - the GroupOperation(for RadFilterGroupExpressionItem), FilterFunction and the editor FieldName.
ToolsInterfaceContainer
Gets the container holding item specific controls. An input control for the RadFilterSingleExpressionItem and AddGroupExpression, AddItemExpression for the RadFilterGroupExpressionItem.
RemoveButton
Gets a reference to the remove button which removes an expression from the RadFilter expression tree.
Gets the associated RadFilterNonGroupExpression.FieldName value
IsSingleValue
Gets a value indicating if the expression item have only one value. If the property returns true the InputControl value will not be null
IsDoubleValue
Gets a value indicating if the expression item have two values (between filtering is performed). If the property returns true the SecondInputControl value will not be null
InputControl
The input control which determines an expression value. The property could return null if the Expression is not of type IRadFilterValueExpression
SecondInputControl
The second input control which determines the second expression value when performing between filtering. The property will not return null only when performing between filtering
FieldNameChooserLink
Gets the HyperLink control which is used for choosing the FieldName
FilterFunctionChooserLink
Gets the HyperLink control which is used for choosing the FilterFunction
BetweenDelimeter
Gets the LiteralControl which is placed between the two input controls when the filter function is "Between" or "NotBetween"