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:
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 |