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

Grouping on Code Behind Issues

2 Answers 591 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael Fuller
Top achievements
Rank 1
Michael Fuller asked on 03 Feb 2010, 09:13 PM
Hello,

I've been trying to work my head around why i receive the following error:

Exception Details: Telerik.Web.UI.GridGroupByException: Field Location not found in the source table. Please check the expression syntax.

In my code the grid is dynamically bound to an XML datasource, so the column names are not constant and change from report to report, but in my current report the "Location" column is supposed to be grouped so that the group footer will display the sum of another column.

  1. The grid is loaded with data on the NeedDataSource function, where a data table is converted to a dataview and sorted.
  2. After the datasource has been set an event lister is added to the grid to listen for ColumnCreated.
  3. In the ColumnCreated function it listens for the creation of the column that needs to be summed, add the neccessary infomation for the row to sum.
  4. Right after adding the sum information the following code block is used to add the grouping:
GridGroupByExpression ge = new GridGroupByExpression();  
GridGroupByField gf = new GridGroupByField();  
gf.FieldName = "Location";  
ge.SelectFields.Add(gf);  
this.RadGrid1.MasterTableView.GroupByExpressions.Add(ge); 
Which leads to the folowing error:

[GridGroupByException: Field Location not found in the source table. Please check the expression syntax.]
   Telerik.Web.UI.GridDataSetHelper.CreateGroupByTable(DataTable SourceTable, GridTableView view) +376
   Telerik.Web.UI.GridEnumerableFromDataView.PerformTransformation() +2698
   Telerik.Web.UI.GridEnumerableFromDataView.TransformEnumerable() +21
   Telerik.Web.UI.GridTableView.GetEnumerator(Boolean useDataSource, GridEnumerableBase resolvedDataSource, ArrayList dataKeysArray) +105
   Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +169
   Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +499
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
   Telerik.Web.UI.GridTableView.PerformSelect() +4
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
   Telerik.Web.UI.GridTableView.DataBind() +238
   Telerik.Web.UI.RadGrid.DataBind() +80
   Telerik.Web.UI.RadGrid.AutoDataBind(GridRebindReason rebindReason) +2122
   Telerik.Web.UI.RadGrid.OnLoad(EventArgs e) +121
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

I know the Location column is present in the data, and I can use the drag up to group feature when the code segment is removed, but I really need it to just do it by itself.

2 Answers, 1 is accepted

Sort by
0
Erwin Floresca
Top achievements
Rank 1
answered on 03 Feb 2010, 10:02 PM
Do you have the field "Location" specified in the grid declaratively? If not you might need to add the column in the "NeedDataSource event".  I didn't use NeedDataSource in my application but this is how I did it.

I get the data from the database and loop through the columns in the datatable and add the grouping and regular columns to the grid. Then I set the datasource of the grid to the datatable and call the grid.databind() method.

I hope this helps.


0
Shinu
Top achievements
Rank 2
answered on 04 Feb 2010, 08:34 AM
Hello Michael,

The steps to build GroupByExpressions programatically for the RadGrid is demonstrated in these online resources. Take a close look at these:
http://demos.telerik.com/aspnet-ajax/grid/examples/groupby/expressions/defaultcs.aspx
http://www.telerik.com/help/aspnet-ajax/grdgroupbyprogrammaticdefinition.html

Make sure that you specify at least one selectfield and one groupbyfield for the dynamically created expression so that grouping functions properly.

Hope this helps.
Shinu.
Tags
Grid
Asked by
Michael Fuller
Top achievements
Rank 1
Answers by
Erwin Floresca
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or