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

GridCalculatedColumn and EnableLinqExpressions=False cause Exception

7 Answers 223 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Constantin
Top achievements
Rank 1
Constantin asked on 26 Sep 2012, 01:22 PM
Hi,

we have encountered a problem with the GridCalculatedColumn and EnableLinqExpressions = false where we receive an Exception on every PageLoad


Minimal Test Case: 

<telerik:RadGrid ID="RadGrid1" DataSourceID="XmlDataSource1" runat="server" Width="990px"
    EnableLinqExpressions="False">
    <MasterTableView AutoGenerateColumns="False">
        <Columns>
            <telerik:GridBoundColumn runat="server" UniqueName="value1" DataField="value1" HeaderText="Value 1" />
            <telerik:GridBoundColumn runat="server" UniqueName="value1" DataField="value1" HeaderText="Value 2" />
            <telerik:GridCalculatedColumn runat="server" Expression="value1 + value2" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
<asp:xmldatasource id="XmlDataSource1" runat="server" datafile="Source.xml" xpath="DataPoints/Point"/>

source.xml
<?xml version="1.0" encoding="utf-8" ?>
<DataPoints>
  <Point Value1="1" Value2="2"/>
</DataPoints>


This yields the Exception:

Server Error in '/Example' Application.

Cannot remove this column, because it is part of an expression: column = value1 + value2.

Description: 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: System.ArgumentException: Cannot remove this column, because it is part of an expression: column = value1 + value2.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 

[ArgumentException: Cannot remove this column, because it is part of an expression: column = value1 + value2.]
   System.Data.DataColumnCollection.CanRemove(DataColumn column, Boolean fThrowException) +1865260
   System.Data.DataColumnCollection.BaseRemove(DataColumn column) +25
   System.Data.DataColumnCollection.Remove(DataColumn column) +53
   Telerik.Web.UI.GridDataTableFromEnumerable.GetColumnsToUse() +6962
   Telerik.Web.UI.GridDataTableFromEnumerable.FillData() +661
   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, Boolean enableSplitHeaderText) +163
   Telerik.Web.UI.GridDataSourceHelper.CreateGridEnumerable(GridTableView owner, IEnumerable enumerable, Boolean caseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields, Boolean enableSplitHeaderText) +129
   Telerik.Web.UI.GridDataSourceHelper.GetResolvedDataSource(GridTableView owner, Object dataSource, String dataMember, Boolean caseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields, Boolean enableSplitHeaderText) +398
   Telerik.Web.UI.GridTableView.get_ResolvedDataSource() +159
   Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +316
   Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +550
   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() +16
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
   Telerik.Web.UI.GridTableView.DataBind() +229
   Telerik.Web.UI.RadGrid.DataBind() +80
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +72
   System.Web.UI.Control.EnsureChildControls() +87
   System.Web.UI.Control.PreRenderRecursiveInternal() +44
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842



Using Telerik Q2-2012-SP2 (2012.2.912.35)

7 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 01 Oct 2012, 12:18 PM
Hello Constantin,

When you are binding through XmlDataSource, each node will become a row and each attribute represents a column. The name of the attribute is the header text of the given column. In this scenario is better to use the GridTemplateColumn instead GridCalculatedColumnd as it is hard to define the data type of the XML items.
<telerik:RadGrid ID="RadGrid2" runat="server" CellSpacing="0" DataSourceID="XmlDataSource1"
    GridLines="None" EnableLinqExpressions="true" OnItemDataBound="RadGrid2_ItemDataBound">
    <MasterTableView AutoGenerateColumns="False" DataSourceID="XmlDataSource1">
        <Columns>
            <telerik:GridBoundColumn DataField="Value1" HeaderText="Value1" SortExpression="Value1"
                UniqueName="Value1">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Value2" HeaderText="Value2" SortExpression="Value2"
                UniqueName="Value2">
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn HeaderText="Total" UniqueName="Temp">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server"></asp:Label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/source.xml"></asp:XmlDataSource>

I also attached the sample so you could take a look at it.

Greetings,
Kostadin
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
Constantin
Top achievements
Rank 1
answered on 01 Oct 2012, 12:53 PM
The problem exists with other DataSources type (for example ObjectDataSource) as well.
This was just a quick sample to give you a test case.

The problem with the GridTemplateColumn is that you lose sorting based on the calculated value, which is what we need the GridCalculatedColumn for to begin with.
0
Kostadin
Telerik team
answered on 02 Oct 2012, 01:59 PM
Hello Constantin,

I was not able to reproduce the same exception with SqlDatasource. I attached a sample where you could see that filtering and sorting work properly when EnableLinqExpressions is set to false. You could check this forum where the same exception is already discussed and might prove helpful in your case.

Regards,
Kostadin
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
Constantin
Top achievements
Rank 1
answered on 02 Oct 2012, 02:53 PM
Hi Kostadin,

thanks for the reply. Working with example I was able to further narrow the problem down. Posting it here for others that may have a similar issue.

You must specify the DataFields you want to use in the expression, regardless of wether you want to use the Placeholder {0} notation or full DataField names in the Expression. If you fail to specify all DataFields used by your Expression you get the Exception mentioned above.

0
Peter
Top achievements
Rank 1
answered on 12 May 2014, 02:16 AM
I don't understand this problem... I simply have a calculated column inside a child DetailsTable in a Rad Grid:

<telerik:GridCalculatedColumn DataFields="" Expression="HourlyRate * 38 * 52" UniqueName="AnnualRateCalc" HeaderText="Annual Rate (Calc)" DataFormatString="{0:c}" DataType="System.Decimal" />

How do I fix this?
0
Princy
Top achievements
Rank 2
answered on 13 May 2014, 06:31 AM
Hi Peter,

You should set the DataFields property of the GridCalculatedColumn and use it in the Expression. Use the DataFields property to list all the fields that are used to calculate the column value. The Expression property specifies how the field values are to be combined, using parameters based on the order of the fields listed in the DataFields property:

ASPX:
<telerik:GridCalculatedColumn DataFields="HourlyRate" Expression="{0} * 38 * 52" . . . />

Thanks,
Princy
0
Peter
Top achievements
Rank 1
answered on 14 May 2014, 06:33 AM
Yes thanks - it's been too long since I used a calculated column... I was thrown-off by the error: "Cannot remove this column, because it is part of an expression: AnnualRateCalc = HourlyRate * 38 * 52."
Tags
Grid
Asked by
Constantin
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Constantin
Top achievements
Rank 1
Peter
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or