This is a migrated thread and some comments may be shown as answers.

How to create multiple "Groups" server side

2 Answers 59 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 2
Richard asked on 25 May 2010, 05:11 PM
I've been working on building the filter expression programmatically with success.  What I can't seem to figure out is how to build multiple groups and apply them to the RadFilter.

I have a datatable with rows.  For each row, I'd like to create a group.  Here's what I have so far but it is now working.

                foreach (DataRow dr in dtFreqUsed.Rows)  
                {  
                    RadFilterGroupExpression grExpression = new RadFilterGroupExpression();  
                    grExpression.GroupOperation = RadFilterGroupOperation.And;  
                    CreateFilterExpression(grExpression, dr);  
                    RadFilter1.RootGroup.Expressions.Add(grExpression);  
                }  
 
 
        protected void CreateFilterExpression(RadFilterGroupExpression grExpression, DataRow dr)  
        {  
            if (!(dr["SEGMENT1"is DBNull) || dr["SEGMENT1"].ToString() != string.Empty)  
            {  
                RadFilterEqualToFilterExpression<string> expr = new RadFilterEqualToFilterExpression<string>("SEGMENT1");  
                expr.Value = dr["SEGMENT1"].ToString();  
                grExpression.AddExpression(expr);  
            }  
            if (!(dr["SEGMENT2"is DBNull) || dr["SEGMENT2"].ToString() != string.Empty)  
            {  
                RadFilterEqualToFilterExpression<string> expr = new RadFilterEqualToFilterExpression<string>("SEGMENT2");  
                expr.Value = dr["SEGMENT2"].ToString();  
                RadFilter1.RootGroup.GroupOperation = RadFilterGroupOperation.And;  
                grExpression.AddExpression(expr);  
            }  
            if (!(dr["SEGMENT3"is DBNull) || dr["SEGMENT3"].ToString() != string.Empty)  
            {  
                RadFilterEqualToFilterExpression<string> expr = new RadFilterEqualToFilterExpression<string>("SEGMENT3");  
                expr.Value = dr["SEGMENT3"].ToString();  
                RadFilter1.RootGroup.GroupOperation = RadFilterGroupOperation.And;  
                grExpression.AddExpression(expr);  
            }  
            if (!(dr["SEGMENT4"is DBNull) || dr["SEGMENT4"].ToString() != string.Empty)  
            {  
                RadFilterEqualToFilterExpression<string> expr = new RadFilterEqualToFilterExpression<string>("SEGMENT4");  
                expr.Value = dr["SEGMENT4"].ToString();  
                RadFilter1.RootGroup.GroupOperation = RadFilterGroupOperation.And;  
                grExpression.AddExpression(expr);  
            }  
            if (!(dr["SEGMENT5"is DBNull) || dr["SEGMENT5"].ToString() != string.Empty)  
            {  
                RadFilterEqualToFilterExpression<string> expr = new RadFilterEqualToFilterExpression<string>("SEGMENT5");  
                expr.Value = dr["SEGMENT5"].ToString();  
                RadFilter1.RootGroup.GroupOperation = RadFilterGroupOperation.And;  
                grExpression.AddExpression(expr);  
            }  
            if (!(dr["SEGMENT6"is DBNull) || dr["SEGMENT6"].ToString() != string.Empty)  
            {  
                RadFilterEqualToFilterExpression<string> expr = new RadFilterEqualToFilterExpression<string>("SEGMENT6");  
                expr.Value = dr["SEGMENT6"].ToString();  
                RadFilter1.RootGroup.GroupOperation = RadFilterGroupOperation.And;  
                grExpression.AddExpression(expr);  
            }  
            if (!(dr["SEGMENT7"is DBNull) || dr["SEGMENT7"].ToString() != string.Empty)  
            {  
                RadFilterEqualToFilterExpression<string> expr = new RadFilterEqualToFilterExpression<string>("SEGMENT7");  
                expr.Value = dr["SEGMENT7"].ToString();  
                RadFilter1.RootGroup.GroupOperation = RadFilterGroupOperation.And;  
                grExpression.AddExpression(expr);  
            }  
            if (!(dr["SEGMENT8"is DBNull) || dr["SEGMENT8"].ToString() != string.Empty)  
            {  
                RadFilterEqualToFilterExpression<string> expr = new RadFilterEqualToFilterExpression<string>("SEGMENT8");  
                expr.Value = dr["SEGMENT8"].ToString();  
                RadFilter1.RootGroup.GroupOperation = RadFilterGroupOperation.And;  
                grExpression.AddExpression(expr);  
            }  
            if (!(dr["SEGMENT9"is DBNull) || dr["SEGMENT9"].ToString() != string.Empty)  
            {  
                RadFilterEqualToFilterExpression<string> expr = new RadFilterEqualToFilterExpression<string>("SEGMENT9");  
                expr.Value = dr["SEGMENT9"].ToString();  
                RadFilter1.RootGroup.GroupOperation = RadFilterGroupOperation.And;  
                grExpression.AddExpression(expr);  
            }  
        }  
 

2 Answers, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 2
answered on 25 May 2010, 08:29 PM
Below is the error message I am getting when I impliment the method posted above.
0
Accepted
Nikolay Rusev
Telerik team
answered on 27 May 2010, 01:27 PM
Hello Richard,

I suspect that you are adding child expressions to the group and after that  the group is added to RootGroup and that is what is causing this error. Please check the following snippet. You should first add the newly created group to root and then append the expressions.

01.protected void Page_Load(object sender, EventArgs e)
02.   {
03.       if (!IsPostBack)
04.       {
05.           RadFilterGroupExpression group = new RadFilterGroupExpression();
06.           group.GroupOperation = RadFilterGroupOperation.And;
07.           RadFilterEqualToFilterExpression<DateTime?> expr = new RadFilterEqualToFilterExpression<DateTime?>("Date");
08.           expr.Value = DateTime.Today.AddDays(1);
09.           RadFilter1.RootGroup.AddExpression(group);           
10.           group.AddExpression(expr);
11.       }        
12.   }

This should do the trick.

Regards,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Filter
Asked by
Richard
Top achievements
Rank 2
Answers by
Richard
Top achievements
Rank 2
Nikolay Rusev
Telerik team
Share this question
or