How to create multiple "Groups" server side

3 posts, 1 answers
  1. Richard
    Richard avatar
    63 posts
    Member since:
    Apr 2008

    Posted 25 May 2010 Link to this post

    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. Richard
    Richard avatar
    63 posts
    Member since:
    Apr 2008

    Posted 25 May 2010 Link to this post

    Below is the error message I am getting when I impliment the method posted above.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 27 May 2010 Link to this post

    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.
Back to Top