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

Dynamic GridCalculatedColumn

3 Answers 210 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Albert Shenker asked on 11 Apr 2009, 05:33 PM
I am creating a grid control through code-behind. I am looping through a list to crerate the columns dynamically. Some of the columns are of type GridCalculatedColumn. For example, my columns are "Total", "Passed" and "PassedPct". The third is the calculated column. When I create this column, I specify its DataFields with...

pctCol.DataFields = New String() {"Passed", "Total"}

and its expression with...

pctCol.Expression = "{0}/{1}"

I am getting an error in the grid databind event and the stack trace (shown below) points to the column experession bind event. It is telling me that:

Cannot find column [Passed].

I commented out the setting of the column expression and the grid was binded, but obviously the calculated column didn't work. I checked to make sure the source columns for the calculated column existed at the point of settting the expression by checking grid.mastertableview.Columns.FindByUniqueName("Passed") and this column exists. So, why is the exprssion not working. Does the expression use some other property (other than UniqueName) to find its component columns?

Or could there be something going on in the Databinding. I create the grid dynamically, set it's mastertableview properties, add dynamic columns,  addthe grid to a panel control on the page, add a handler for the grid's ItemDataBound Event, set the datasource of the grid and call databind, all in that order. All of this occurs within the page load event. Is there something I am missing about binding a dynamically created grid that could be causing the issue?

Stack Trace:
 
[EvaluateException: Cannot find column [Passed].]  
 
   
System.Data.NameNode.Bind(DataTable table, List`1 list) +1186845  
   System.Data.DataExpression.Bind(DataTable table) +59  
   System.Data.DataColumn.SetTable(DataTable table) +4826220  
   System.Data.DataColumnCollection.BaseAdd(DataColumn column) +272  
   System.Data.DataColumnCollection.AddAt(Int32 index, DataColumn column) +78  
   System.Data.DataColumnCollection.Add(DataColumn column) +8  
   Telerik.Web.UI.GridDataTableFromEnumerable.GetColumnsToUse() +1020  
   Telerik.Web.UI.GridDataTableFromEnumerable.FillData() +68  
   Telerik.Web.UI.GridResolveEnumerable.Initialize() +32  
   Telerik.Web.UI.GridResolveEnumerable.EnsureInitialized() +20  
   Telerik.Web.UI.GridEnumerableFromDataView..ctor(GridTableView owner, IEnumerable enumerable, Boolean CaseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields) +158  
   Telerik.Web.UI.GridDataSourceHelper.CreateGridEnumerable(GridTableView owner, IEnumerable enumerable, Boolean caseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields) +129  
   Telerik.Web.UI.GridDataSourceHelper.GetResolvedDataSource(GridTableView owner, Object dataSource, String dataMember, Boolean caseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields) +383  
   Telerik.Web.UI.GridTableView.get_ResolvedDataSource() +140  
   Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +33  
   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() +239  
   Telerik.Web.UI.RadGrid.DataBind() +80  
 

3 Answers, 1 is accepted

Sort by
0
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
answered on 12 Apr 2009, 03:04 PM

As an addendum.. I tried adding an aggregate to one of the "Numeric" columns (in other words, not one of the CalculatedCOlumns) and I got a similar error. Do some of the Rag grid functions, such as calculated columns and footer aggregates not work particularly well when creating the grid server-side?

Trace:

[ArgumentException: Column 'Total' does not belong to table .]  
   System.Data.DataRow.GetDataColumn(String columnName) +1773557  
   System.Data.DataRow.get_Item(String columnName) +13  
   Telerik.Web.UI.GridDataSetHelper.CalculateAggregates(DataRow SourceRow, DataRow DestRow, Int32 rowCountInGroup, GridTableView view) +704  
   Telerik.Web.UI.GridDataSetHelper.InsertGroupByInto(GridTableView gridTableView, DataTable DestTable, DataTable SourceTable, String RowFilter, Int32 FirstIndexInPage, Int32 LastIndexInPage, Boolean ApplyPaging, Boolean IsCustomPaging) +677  
   Telerik.Web.UI.GridEnumerableFromDataView.PerformTransformation() +2740  
   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() +239  
   Telerik.Web.UI.RadGrid.DataBind() +80  
 
0
Yavor
Telerik team
answered on 14 Apr 2009, 08:49 AM
Hi Albert,

Basically, there should be no problems creating the grid control, or its structure and columns dynamically, regardless of the column types. To further trace the issue, however, it will be best if you open a formal support ticket, and send us a small working project, demonstrating your setup, along with the unwanted behavior. We will review it locally, and advise you further.

Greetings,
Yavor
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Bhaskar
Top achievements
Rank 1
answered on 20 Nov 2015, 01:44 PM
Server Error in '/' Application.

')' or ',' expectedDescription: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: Telerik.Web.UI.ParseException: ')' or ',' expected

Source Error: 

Line 100: Line 101: ddd.DataSource = dt; Line 102: ddd.DataBind(); Line 103: ddd.Width = 1250; Line 104: ddd.HeaderStyle.CssClass = "rowstyle";
Source File: e:\SSIS\MISDEIFFINALPROJECT\Deif-MIS\Deif-MIS\client\Salesbudgetdashboard.aspx.cs    Line: 102 

Stack Trace: 

[ParseException: ')' or ',' expected] Telerik.Web.UI.ExpressionParser.ValidateToken(TokenId t, String errorMessage) +103 Telerik.Web.UI.ExpressionParser.ParseNew() +552 Telerik.Web.UI.ExpressionParser.ParseIdentifier() +285 Telerik.Web.UI.ExpressionParser.ParsePrimaryStart() +83 Telerik.Web.UI.ExpressionParser.ParsePrimary() +47 Telerik.Web.UI.ExpressionParser.ParseUnary() +404 Telerik.Web.UI.ExpressionParser.ParseMultiplicative() +54 Telerik.Web.UI.ExpressionParser.ParseAdditive() +54 Telerik.Web.UI.ExpressionParser.ParseComparison() +69 Telerik.Web.UI.ExpressionParser.ParseLogicalAnd() +49 Telerik.Web.UI.ExpressionParser.ParseLogicalOr() +49 Telerik.Web.UI.ExpressionParser.ParseExpression() +74 Telerik.Web.UI.ExpressionParser.Parse(Type resultType) +76 Telerik.Web.UI.DynamicExpression.ParseLambda(ParameterExpression[] parameters, Type resultType, String expression, Object[] values) +92 Telerik.Web.UI.DynamicExpression.ParseLambda(Type itType, Type resultType, String expression, Object[] values) +132 Telerik.Web.UI.GridDynamicQueryable.Select(IQueryable source, String selector, Object[] values) +226 Telerik.Web.UI.GridDataTableFromEnumerable.FillData35() +2961 Telerik.Web.UI.GridDataTableFromEnumerable.FillData() +1077 Telerik.Web.UI.GridResolveEnumerable.Initialize() +58 Telerik.Web.UI.GridResolveEnumerable.EnsureInitialized() +45 Telerik.Web.UI.GridResolveEnumerable.get_DataTable() +36 Telerik.Web.UI.GridEnumerableFromDataView..ctor(GridTableView owner, DataView dataView, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields, Boolean enableSplitHeaderText) +245 Telerik.Web.UI.GridDataSourceHelper.CreateGridEnumerable(GridTableView owner, IEnumerable enumerable, Boolean caseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields, Boolean enableSplitHeaderText) +109 Telerik.Web.UI.GridDataSourceHelper.GetResolvedDataSource(GridTableView owner, Object dataSource, String dataMember, Boolean caseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields, Boolean enableSplitHeaderText) +322 Telerik.Web.UI.GridTableView.get_ResolvedDataSource() +256 Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +842 System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +67 System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +123 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +33 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +138 Telerik.Web.UI.GridTableView.PerformSelect() +38 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30 Telerik.Web.UI.GridTableView.DataBind() +392 Telerik.Web.UI.RadGrid.DataBind() +191 Deif_MIS.client.Salesbudgetdashboard.BindDataEMPcalculation() in e:\SSIS\MISDEIFFINALPROJECT\Deif-MIS\Deif-MIS\client\Salesbudgetdashboard.aspx.cs:102 Deif_MIS.client.Salesbudgetdashboard.Page_Load(Object sender, EventArgs e) in e:\SSIS\MISDEIFFINALPROJECT\Deif-MIS\Deif-MIS\client\Salesbudgetdashboard.aspx.cs:49 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51 System.Web.UI.Control.OnLoad(EventArgs e) +92 System.Web.UI.Control.LoadRecursive() +54 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34274
Tags
Grid
Asked by
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Answers by
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Yavor
Telerik team
Bhaskar
Top achievements
Rank 1
Share this question
or