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

[Solved] Telerik grid Group By Expression Error

2 Answers 182 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Wella
Top achievements
Rank 1
Wella asked on 30 Apr 2013, 10:00 AM

I have try group telerik grid using drop down list

grouping method source code is bellow

 try
        {

            this.grd.MasterTableView.GroupByExpressions.Clear();//clear all group expressions
            grd.MasterTableView.GroupsDefaultExpanded = false;

            GridGroupByExpression expression = new GridGroupByExpression();
            GridGroupByField gridGroupByField = new GridGroupByField();
            gridGroupByField = new GridGroupByField();
            if (cboGroupByItem1.SelectedValue != "0")
            {
                gridGroupByField.FieldName = cboGroupByItem1.SelectedValue;
                gridGroupByField.HeaderText = cboGroupByItem1.SelectedItem.Text;
                expression.SelectFields.Add(gridGroupByField);
            }

            if (cboGroupByItem2.SelectedValue != "0")
            {
                gridGroupByField.FieldName = cboGroupByItem2.SelectedValue;
                gridGroupByField.HeaderText = cboGroupByItem2.SelectedItem.Text;
                expression.SelectFields.Add(gridGroupByField);
            }

            grd.MasterTableView.GroupByExpressions.Add(expression);


        }
        catch (Exception ex)
        {
            label1.Text = ex.ToString();
        }
        finally
        {
            grd.Rebind();
        }

when grid rebind method it will generate bellow error

An error occured adding a relation to DataRelationCollection. Please, make sure you have configured the expressions properly - both GroupByFields and SelectFields are required!

How i solve this question please help me

2 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 03 May 2013, 05:20 AM
Hi Wella,

You need also to add the created GridGroupField to the GroupByFields collection of the expression:
protected void Button1_Click(object sender, EventArgs e)
{
    RadGrid1.MasterTableView.GroupByExpressions.Clear();//clear all group expressions
    RadGrid1.MasterTableView.GroupsDefaultExpanded = false;
 
    GridGroupByExpression expression = new GridGroupByExpression();
    GridGroupByField gridGroupByField = new GridGroupByField();
 
    gridGroupByField.FieldName = "ShipCountry";
    gridGroupByField.HeaderText = "ShipCountry";
    expression.GroupByFields.Add(gridGroupByField);
    expression.SelectFields.Add(gridGroupByField);
 
    RadGrid1.MasterTableView.GroupByExpressions.Add(expression);
 
    RadGrid1.Rebind();
}

Please check out this demo for a reference:
http://demos.telerik.com/aspnet-ajax/grid/examples/groupby/groupfooter/defaultcs.aspx

Hope this helps.

Greetings,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Wella
Top achievements
Rank 1
answered on 03 May 2013, 05:35 AM
ThanK You Very much .

It's Solved my Problem.
Tags
Grid
Asked by
Wella
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Wella
Top achievements
Rank 1
Share this question
or